{"id":361146,"date":"2024-05-21T01:07:30","date_gmt":"2024-05-21T01:07:30","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=361146"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-05-21T01:07:30","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=361146","title":{"rendered":"<span>\u0425\u0438\u043c\u0438\u044f \u0432 Python: \u0427\u0430\u0441\u0442\u044c 2<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><a href=\"https:\/\/habr.com\/ru\/articles\/774918\/\" rel=\"noopener noreferrer nofollow\">\u041f\u0440\u043e\u0448\u043b\u0430\u044f \u043c\u043e\u044f \u0441\u0442\u0430\u0442\u044c\u044f<\/a> \u043d\u0430\u0431\u0440\u0430\u043b\u0430 \u0445\u043e\u0440\u043e\u0448\u0438\u0439 \u043e\u0442\u043a\u043b\u0438\u043a.<\/p>\n<p>\u0418 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0440\u0435\u0448\u0438\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<p>\u0418\u0442\u0430\u043a, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u044f \u043d\u0435 \u0441\u043c\u043e\u0433\u0443 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0441\u0435, \u0447\u0442\u043e \u0445\u043e\u0442\u0435\u043b\u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0442\u043e\u0440\u044b \u0432 \u043f\u0440\u043e\u0448\u043b\u043e\u043c \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0435, \u043d\u043e \u044f \u043f\u043e\u0441\u0442\u0440\u0430\u044e\u0441\u044c \u0432\u044b\u043b\u043e\u0436\u0438\u0442\u044c\u0441\u044f, \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0443.<\/p>\n<p>\u0425\u043e\u0447\u0443 \u043d\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u0432 <a href=\"https:\/\/habr.com\/ru\/articles\/775464\/\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u044f \u0442\u0430\u043a\u0436\u0435 \u0443\u0434\u0435\u043b\u0438\u043b \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043a\u043e\u0434\u0443.<\/p>\n<p>\u041d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u044e, \u0447\u0442\u043e \u0432\u0435\u0441\u044c <a href=\"https:\/\/github.com\/OkulusDev\/Oxygen\" rel=\"noopener noreferrer nofollow\">\u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 &#8212; \u0437\u0434\u0435\u0441\u044c, \u043d\u0430 \u043c\u043e\u0435\u043c GitHub&#8217;\u0435.<\/a><\/p>\n<h2>\u0420\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433 \u043a\u043e\u0434\u0430<\/h2>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u043b \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043f\u0443\u0442\u0435\u043c \u043a\u043e\u043f\u0438\u043f\u0430\u0441\u0442\u0438\u043d\u0433\u0430 \u0438 \u0440\u0443\u0447\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e\u0431 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0445.<\/p>\n<p>\u041d\u043e \u044f \u0440\u0435\u0448\u0438\u043b, \u0447\u0442\u043e \u043b\u0443\u0447\u0448\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0433\u043e\u0442\u043e\u0432\u043e\u0433\u043e csv-\u0444\u0430\u0439\u043b\u0430 \u0441 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439 \u043e\u0431\u043e \u0432\u0441\u0435\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0445.<\/p>\n<p>\u0410 \u0442\u0430\u043a\u0436\u0435, \u0432\u043c\u0435\u0441\u0442\u043e \u043f\u0440\u044f\u043c\u043e\u0433\u043e \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f, \u044f \u0441\u043e\u0437\u0434\u0430\u044e \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f \u0441\u043f\u0438\u0441\u043e\u043a \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0441\u043a\u0430\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043f\u043e \u0440\u0430\u0437\u043d\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c.<\/p>\n<p><a href=\"https:\/\/gist.github.com\/GoodmanSciences\/c2dd862cd38f21b0ad36b8f96b4bf1ee\" rel=\"noopener noreferrer nofollow\">\u0422\u0430\u0431\u043b\u0438\u0446\u0430 \u0441 \u0445\u0438\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u0437\u0434\u0435\u0441\u044c.<\/a><\/p>\n<p>\u041d\u0430\u043c \u043d\u0430\u0434\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0444\u0430\u0439\u043b \u0441 \u0445\u0438\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438:<\/p>\n<pre><code class=\"python\">#!\/usr\/bin\/python3 # -*- coding:utf-8 -*- \"\"\" Oxygen Library --------------------------------------------------------------------------------  \u0410\u0432\u0442\u043e\u0440: Okulus Dev (aka DrArgentum)  \u041b\u0438\u0446\u0435\u043d\u0437\u0438\u044f: GNU GPL v3 --------------------------------------------------------------------------------  \u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435: \u0444\u0430\u0439\u043b \u0441 \u0445\u0438\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438  Copyright (C) 2023  Okulus Dev This program is free software: you can redistribute it and\/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program.  If not, see &lt;https:\/\/www.gnu.org\/licenses\/>. \"\"\" import csv from typing import Union   def round_to_nearest(num: int):     num = int(num + (0.5 if num > 0 else -0.5))     return num   class Element:     def __init__(self, atomic_number: int, name: str, symbol: str, atomic_mass: float,                 neutrons: int, protons: int, electrons: int, period: int, group: int,                 phase: str, radioctive: bool, natural: bool, metall: bool, nonmetall: bool,                 metalloid: bool, element_type: str):         self.atomic_number = int(atomic_number)         self.name = name         self.short_name = symbol         self.relative_atomic_mass = float(atomic_mass)         self.neutrons = int(neutrons)         self.protons = int(protons)         self.electrons = int(electrons)         self.period = int(period)         self.group = group         self.phase = phase         if natural == '':             self.natural = False         else:             self.natural = True         if radioctive == '':             self.radioctive = False         else:             self.radioctive = True         if metall == '':             self.metall = False         else:             self.metall = True         if nonmetall == '':             self.nonmetall = False         else:             self.nonmetall = True         if metalloid == '':             self.metalloid = False         else:             self.metalloid = True         if element_type == '':             self.element_type = 'Unknown'         else:             self.element_type = element_type   AVOGADRO_NUMBER = 6.02214076e23 ELEMENTS = []  # \u043f\u0443\u0442\u044c \u0434\u043e csv \u0444\u0430\u0439\u043b\u0430 with open('oxygen\/chemistry\/data\/PeriodicTable.csv', newline='') as File:     reader = csv.reader(File)     c = 0     for row in reader:         if c == 0:             c += 1             continue         # \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432\u043f\u043b\u043e\u0442\u044c \u0434\u043e \u0442\u0438\u043f\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430         # todo: \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u043e\u043b\u044f         ELEMENTS.append(Element(row[0], row[1], row[2], row[3], row[4], row[5],                                 row[6], row[7], row[8], row[9], row[10],                                 row[11], row[12], row[13], row[14], row[15]))   class MendeleevTable:     def __init__(self, elements: list) -> None:         self.elements = elements      def get_element_by_shortname(self, shortname: str) -> Union[Element, None]:         for element in self.elements:             if element.short_name == shortname:                 return element          return None      def get_element_by_name(self, name: str) -> Union[Element, None]:         for element in self.elements:             if element.name == name:                 return element          return None      def get_element_by_number(self, num: int) -> Union[Element, None]:         for element in self.elements:             if element.atomic_number == num:                 return element          return None   MendeleevTable = MendeleevTable(ELEMENTS)<\/code><\/pre>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435, \u0447\u0442\u043e \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f &#8212; \u044d\u0442\u043e \u043a\u043b\u0430\u0441\u0441 \u0445\u0438\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0444\u043e\u0440\u043c\u0443\u043b\u044b. \u0415\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0432\u0432\u0435\u043b \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u0445\u0438\u043c\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0444\u043e\u0440\u043c\u0443\u043b\u0443, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u0430\u0445\u0430\u0440\u043e\u0437\u0443 \u0438\u043b\u0438 \u0432\u043e\u0434\u0443, \u0442\u043e \u043c\u044b \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e\u0431 \u044d\u0442\u043e\u043c<\/p>\n<pre><code class=\"python\">\"\"\" Copyright (C) 2023  Okulus Dev This program is free software: you can redistribute it and\/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program.  If not, see &lt;https:\/\/www.gnu.org\/licenses\/>. \"\"\" # \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u043f\u043e\u0440\u0442 \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440\u0430 \u043c\u043e\u043b\u0435\u043a\u0443\u043b\u044f\u0440\u043d\u043e\u0439 \u043c\u0430\u0441\u0441\u044b, \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u0437\u0434\u0435\u0441\u044c \u0432\u0441\u0435 \u0435\u0441\u0442\u044c # \u043d\u043e \u0442.\u043a. \u044d\u0442\u043e \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b, \u0442\u043e \u044f \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u0432\u044b \u0441\u0430\u043c\u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0439\u0442\u0435 \u0438\u043b\u0438 \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u0435 \u043a\u043e\u0434 # (\u0434\u0430\u0431\u044b \u043d\u0435 \u0437\u0430\u043f\u0443\u0442\u0430\u0442\u044c \u0432\u0430\u0441)   class ChemicalFormula:     \"\"\"\u041a\u043b\u0430\u0441\u0441 \u0445\u0438\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0444\u043e\u0440\u043c\u0443\u043b\u044b\"\"\"     def __init__(self, elements: dict, formula: str,                  name: str, molecular_mass: float=None):         self.elements = elements         self.formula = formula         if molecular_mass is not None:             self.molecular_mass = molecular_mass         else:             self.molucular_mass = calculate_relative_molecular_mass(formula, False)         self.name = name   # \u0425\u0438\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0444\u043e\u0440\u043c\u0443\u043b\u044b CHEMICAL_FORMULAS = {     'H2O': ChemicalFormula({('H', 2), ('O', 1)}, \"H2O\", '\u0412\u043e\u0434\u0430', None),     'C12H22O11': ChemicalFormula({('C', 12), ('H', 22), ('O', 11)},                                  \"C12H22O11\", '\u0421\u0430\u0445\u0430\u0440\u043e\u0437\u0430 (\u0441\u0430\u0445\u0430\u0440)', None) }   def read_formula(formula: str):     \"\"\"\u0427\u0438\u0442\u0430\u0435\u043c \u0444\u043e\u0440\u043c\u0443\u043b\u0443 \u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0435\u0435, \u0435\u0441\u043b\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u0430\u043a\u043e\u0432\u0430\u044f\"\"\"     if formula in CHEMICAL_FORMULAS:         print(f'\u0424\u043e\u0440\u043c\u0443\u043b\u0430 {formula} \u044d\u0442\u043e - {CHEMICAL_FORMULAS[formula].name}')         elements_in_formula = []          for el in CHEMICAL_FORMULAS[formula].elements:             elements_in_formula.append(f\"{el[1]} {MendeleevTable.get_element_by_shortname(el[0]).name}\")          elements_in_formula_str = \", \".join(elements_in_formula)         print(f'{CHEMICAL_FORMULAS[formula].name} \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 {elements_in_formula_str}')<\/code><\/pre>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043a\u043e\u0434.<\/p>\n<pre><code class=\"python\">#!venv\/bin\/python3 \"\"\" Oxygen Library --------------------------------------------------------------------------------  \u0410\u0432\u0442\u043e\u0440: Okulus Dev (aka DrArgentum)  \u041b\u0438\u0446\u0435\u043d\u0437\u0438\u044f: GNU GPL v3 --------------------------------------------------------------------------------  \u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435: \u0411\u0430\u0437\u043e\u0432\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0445\u0438\u043c\u0438\u0438 \u0432 \u0432\u0430\u0448\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445   \u041f\u0435\u0440\u0435\u0447\u0435\u043d\u044c:    1. \u041f\u0430\u0440\u0441\u0438\u043d\u0433 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0438\u0437 \u0444\u043e\u0440\u043c\u0443\u043b\u044b    2. \u0412\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043c\u043e\u043b\u0435\u043a\u0443\u043b\u044f\u0440\u043d\u043e\u0439 \u043c\u0430\u0441\u0441\u044b    3. \u0412\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043c\u0430\u0441\u0441\u043e\u0432\u043e\u0439 \u0434\u043e\u043b\u0438  Copyright (C) 2023  Okulus Dev This program is free software: you can redistribute it and\/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program.  If not, see &lt;https:\/\/www.gnu.org\/licenses\/>. \"\"\" import re from collections import Counter # \u0437\u0434\u0435\u0441\u044c \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u0438\u043c\u043f\u043e\u0440\u0442 \u0438\u043b\u0438 \u0432\u0441\u0442\u0430\u0432\u043a\u0430 \u043a\u043e\u0434\u0430 \u0445\u0438\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430   def repl(m):     return m[1] * int(m[2] if m[2] else 1)   def is_balanced(text, brackets=\"\u3008\u3009()[]{}\"):     opening, closing = brackets[::2], brackets[1::2]     stack = []     for character in text:         if character in opening:             stack.append(opening.index(character))         elif character in closing:             if stack and stack[-1] == closing.index(character):                 stack.pop()               else:                 return False     return (not stack)     def parse_molecule(formula: str) -> dict:     \"\"\"\u041f\u0430\u0440\u0441\u0438\u043d\u0433 \u043c\u043e\u043b\u0435\u043a\u0443\u043b\u044b\"\"\"     if not is_balanced(formula):         raise ValueError(f\"Brackets in {formula} is not balanced\")         sys.exit()          while '(' in formula:         formula = re.sub(r'\\((\\w*)\\)(\\d*)', repl, formula)     while '[' in formula:         formula = re.sub(r'\\[(\\w*)\\](\\d*)', repl, formula)     formula = re.sub(r'([A-Z][a-z]?)(\\d*)', repl, formula)     formula_dict = Counter(re.findall('[A-Z][a-z]*', formula))      return formula_dict   def get_element_mass(element: str):     \"\"\"\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043c\u0430\u0441\u0441\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043f\u043e \u0435\u0433\u043e \u0445\u0438\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u043c\u0443 \u0437\u043d\u0430\u0447\u043a\u0443\"\"\"     try:         return MendeleevTable.get_element_by_shortname(element).relative_atomic_mass     except:         raise ValueError(f\"Element {element} does not exists. Try other!\")         sys.exit()  def calculate_mass_fraction_of_element(formula: str, element: str):     \"\"\"\u0412\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u043c\u0430\u0441\u0441\u043e\u0432\u0443\u044e \u0434\u043e\u043b\u044e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432 \u0444\u043e\u0440\u043c\u0443\u043b\u0435\"\"\"     formula = parse_molecule(formula)     mass_fraction = 0     mass = 0      for i in formula.items():         mass += get_element_mass(i[0]) * i[1]      for i in formula.items():         if MendeleevTable.get_element_by_shortname(i[0]).short_name == element:             mass_fraction = (get_element_mass(i[0]) * i[1] \/ mass) * 100             break      return mass_fraction   def calculate_relative_molecular_mass(formula: str, print_info: bool=False) -> dict:     \"\"\"\u0412\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u043c\u0430\u0441\u0441\u043e\u0432\u0443\u044e \u0434\u043e\u043b\u044e \u0444\u043e\u0440\u043c\u0443\u043b\u044b\"\"\"     result = parse_molecule(formula)     mass = 0     neutrons = 0     electrons = 0     protons = 0      for i in result.items():         try:             if print_info:                 print(f'{i[1]} {MendeleevTable.get_element_by_shortname([i[0]][0]).name} = \\ {MendeleevTable.get_element_by_shortname([i[0]][0]).relative_atomic_mass * i[1]}')                 print(f'\u041a\u043e\u043b-\u0432\u043e \u043f\u0440\u043e\u0442\u043e\u043d\u043e\u0432 \u0432 {MendeleevTable.get_element_by_shortname([i[0]][0]).short_name} \\ ({MendeleevTable.get_element_by_shortname([i[0]][0]).name}): {MendeleevTable.get_element_by_shortname([i[0]][0]).protons}')                 print(f'\u041a\u043e\u043b-\u0432\u043e \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043e\u0432 \u0432 {MendeleevTable.get_element_by_shortname([i[0]][0]).short_name} \\ ({MendeleevTable.get_element_by_shortname([i[0]][0]).name}): {MendeleevTable.get_element_by_shortname([i[0]][0]).electrons}')                 print(f'\u041a\u043e\u043b-\u0432\u043e \u043d\u0435\u0439\u0442\u0440\u043e\u043d\u043e\u0432 \u0432 {MendeleevTable.get_element_by_shortname([i[0]][0]).short_name} \\ ({MendeleevTable.get_element_by_shortname([i[0]][0]).name}): {MendeleevTable.get_element_by_shortname([i[0]][0]).neutrons}')              neutrons += MendeleevTable.get_element_by_shortname([i[0]][0]).neutrons * i[1]             electrons += MendeleevTable.get_element_by_shortname([i[0]][0]).electrons * i[1]             protons += MendeleevTable.get_element_by_shortname([i[0]][0]).protons * i[1]              mass += get_element_mass(i[0]) * i[1]         except Exception as e:             print(e)             raise ValueError(f'Element {i[0]} does not exists. Try other!')      return {         'mass': mass,         'electrons': electrons,         'neutrons': neutrons,         'protons': protons     } <\/code><\/pre>\n<p>\u0418 \u043f\u043e\u0442\u043e\u043c \u043c\u044b \u0432\u0441\u0435 \u044d\u0442\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u043a \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c\u043e\u043c\u0443 \u0444\u0430\u0439\u043b\u0443:<\/p>\n<pre><code class=\"python\">#!\/usr\/bin\/python3 # -*- coding:utf-8 -*- \"\"\" --------------------------------------------------------------------------------  \u0410\u0432\u0442\u043e\u0440: Okulus Dev (aka DrArgentum)  \u041b\u0438\u0446\u0435\u043d\u0437\u0438\u044f: GNU GPL v3  \u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435: \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0444\u0430\u0439\u043b  \u0424\u0430\u0439\u043b: oxygen.py --------------------------------------------------------------------------------  \u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435: \u0413\u043b\u0430\u0432\u043d\u044b\u0439 \u0444\u0430\u0439\u043b, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0438\u043c\u043f\u043e\u0440\u0442\u044b \u0432\u0441\u0435\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0439  Copyright (C) 2023  Okulus Dev This program is free software: you can redistribute it and\/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program.  If not, see &lt;https:\/\/www.gnu.org\/licenses\/>. \"\"\" import argparse import textwrap # from oxygen.chemistry.base import calculate_relative_molecular_mass, \\ #                                     calculate_mass_fraction_of_element # from oxygen.chemistry.formulas import read_formula # \u0441\u0432\u0435\u0440\u0445\u0443 \u044f \u043f\u0440\u0438\u0432\u0435\u043b \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043d\u0443\u0436\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0432\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0438\u0445 \u043a\u043e\u0434 \u0441\u044e\u0434\u0430 \u0438\u043b\u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0439\u0442\u0435 \u0438\u0445 \u0441\u0430\u043c\u0438   def get_molecular_mass_from_formule(formula):     print(f'\u0420\u0430\u0441\u0447\u0435\u0442 \u0444\u043e\u0440\u043c\u0443\u043b\u044b {formula}:\\n')     mass = calculate_relative_molecular_mass(formula, True)      if mass is not None:         print(f'\u041e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u043c\u043e\u043b\u0435\u043a\u0443\u043b\u044f\u0440\u043d\u0430\u044f \u043c\u0430\u0441\u0441\u0430 \u0444\u043e\u0440\u043c\u0443\u043b\u044b {formula} = ~{mass[\"mass\"]}')         print(f'\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0442\u043e\u043d\u043e\u0432 \u0432 \u0444\u043e\u0440\u043c\u0443\u043b\u0435 {formula} = ~{mass[\"protons\"]}')         print(f'\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043e\u0432 \u0432 \u0444\u043e\u0440\u043c\u0443\u043b\u0435 {formula} = ~{mass[\"electrons\"]}')         print(f'\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043d\u0435\u0439\u0442\u0440\u043e\u043d\u043e\u0432 \u0432 \u0444\u043e\u0440\u043c\u0443\u043b\u0435 {formula} = ~{mass[\"neutrons\"]}')     else:         print(f'\u041e\u0448\u0438\u0431\u043a\u0430 \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 \u0444\u043e\u0440\u043c\u0443\u043b\u044b {formula}')   def main():     parser = argparse.ArgumentParser(prog='Oxygen Library', allow_abbrev=True,                             description='Oxygen',                             formatter_class=argparse.RawDescriptionHelpFormatter,     epilog=textwrap.dedent(''' \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f:  # \u0412\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0440\u0435\u0436\u0438\u043c \u0445\u0438\u043c\u0438\u0438 oxygen.py -c  # \u0412\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043c\u043e\u043b\u0435\u043a\u0443\u043b\u044f\u0440\u043d\u043e\u0439 \u043c\u0430\u0441\u0441\u044b \u0444\u043e\u0440\u043c\u0443\u043b\u044b oxygen.py -c -rmm &lt;\u0424\u041e\u0420\u041c\u0423\u041b\u0410>  # \u0412\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043c\u0430\u0441\u0441\u043e\u0432\u043e\u0439 \u0434\u043e\u043b\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432 \u0444\u043e\u0440\u043c\u0443\u043b\u0435 oxygen.py -c -mf &lt;\u0424\u041e\u0420\u041c\u0423\u041b\u0410> -mfe &lt;\u042d\u041b\u0415\u041c\u0415\u041d\u0422 \u0418\u0417 \u0424\u041e\u0420\u041c\u0423\u041b\u042b>  # \u0412\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043c\u043e\u043b\u0435\u043a\u0443\u043b\u044f\u0440\u043d\u043e\u0439 \u043c\u0430\u0441\u0441\u044b \u0444\u043e\u0440\u043c\u0443\u043b\u044b \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c \u0444\u043e\u0440\u043c\u0443\u043b\u044b \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e \u0432\u0435\u0449\u0435\u0441\u0442\u0432\u0430 oxygen.py -cr -rmm &lt;\u0424\u041e\u0420\u041c\u0423\u041b\u0410>  # \u0412\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043c\u0430\u0441\u0441\u043e\u0432\u043e\u0439 \u0434\u043e\u043b\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432 \u0444\u043e\u0440\u043c\u0443\u043b\u0435 \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c \u0444\u043e\u0440\u043c\u0443\u043b\u044b \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e \u0432\u0435\u0449\u0435\u0441\u0442\u0432\u0430 oxygen.py -cr -mf &lt;\u0424\u041e\u0420\u041c\u0423\u041b\u0410> -mfe &lt;\u042d\u041b\u0415\u041c\u0415\u041d\u0422 \u0418\u0417 \u0424\u041e\u0420\u041c\u0423\u041b\u042b>  Copyright Okulus Dev (C) 2023 '''))     parser.add_argument('-c', '--chemistry-mode', help='\u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043c\u043e\u0434 \u0445\u0438\u043c\u0438\u0438',                         action='store_true')     parser.add_argument('-r', '--read-formula', help='\u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0447\u0442\u0435\u043d\u0438\u0435 \u0444\u043e\u0440\u043c\u0443\u043b\u044b',                         action='store_true', default=False)     parser.add_argument('-rmm', '--relative-molecular-mass',                         help='\u0440\u0430\u0441\u0441\u0447\u0435\u0442 \u043c\u043e\u043b\u0435\u043a\u0443\u043b\u044f\u0440\u043d\u043e\u0439 \u043c\u0430\u0441\u0441\u044b \u0444\u043e\u0440\u043c\u0443\u043b\u044b')     parser.add_argument('-mf', '--mass-fraction', metavar='\u0424\u041e\u0420\u041c\u0423\u041b\u0410',                         help='\u0440\u0430\u0441\u0441\u0447\u0435\u0442 \u043c\u0430\u0441\u0441\u043e\u0432\u043e\u0439 \u0434\u043e\u043b\u0438 \u0432 \u0444\u043e\u0440\u043c\u0443\u043b\u0435')     parser.add_argument('-mfe', '--mf-element', metavar='\u0424\u041e\u0420\u041c\u0423\u041b\u0410',                         help='\u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0440\u0430\u0441\u0441\u0447\u0435\u0442\u0430 \u043c\u0430\u0441\u0441\u043e\u0432\u043e\u0439 \u0434\u043e\u043b\u0438')     args = parser.parse_args()      if args.chemistry_mode:         if args.relative_molecular_mass:             get_molecular_mass_from_formule(args.relative_molecular_mass)             if args.read_formula:                 read_formula(args.relative_molecular_mass)         elif args.mass_fraction:             if args.mf_element:                 res = calculate_mass_fraction_of_element(args.mass_fraction,                                                           args.mf_element)                 if args.read_formula:                     read_formula(args.mass_fraction)                 print(f\"\u041c\u0430\u0441\u0441\u043e\u0432\u0430\u044f \u0434\u043e\u043b\u044f {args.mf_element} \u0432 \\ {args.mass_fraction}: {res}%\")             else:                 print('\u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0432\u044b \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u043b\u0438 \u043d\u0443\u0436\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442.')                 if args.read_formula:                     read_formula(args.mass_fraction)   if __name__ == \"__main__\":     main() <\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c\u0441\u044f. \u042f \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u043f\u0430\u0440\u0441\u0435\u0440 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 argparse.<\/p>\n<pre><code>\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f:  # \u0412\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0440\u0435\u0436\u0438\u043c \u0445\u0438\u043c\u0438\u0438 oxygen.py -c  # \u0412\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043c\u043e\u043b\u0435\u043a\u0443\u043b\u044f\u0440\u043d\u043e\u0439 \u043c\u0430\u0441\u0441\u044b \u0444\u043e\u0440\u043c\u0443\u043b\u044b oxygen.py -c -rmm &lt;\u0424\u041e\u0420\u041c\u0423\u041b\u0410>  # \u0412\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043c\u0430\u0441\u0441\u043e\u0432\u043e\u0439 \u0434\u043e\u043b\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432 \u0444\u043e\u0440\u043c\u0443\u043b\u0435 oxygen.py -c -mf &lt;\u0424\u041e\u0420\u041c\u0423\u041b\u0410> -mfe &lt;\u042d\u041b\u0415\u041c\u0415\u041d\u0422 \u0418\u0417 \u0424\u041e\u0420\u041c\u0423\u041b\u042b>  # \u0412\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043c\u043e\u043b\u0435\u043a\u0443\u043b\u044f\u0440\u043d\u043e\u0439 \u043c\u0430\u0441\u0441\u044b \u0444\u043e\u0440\u043c\u0443\u043b\u044b \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c \u0444\u043e\u0440\u043c\u0443\u043b\u044b \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e \u0432\u0435\u0449\u0435\u0441\u0442\u0432\u0430 oxygen.py -cr -rmm &lt;\u0424\u041e\u0420\u041c\u0423\u041b\u0410>  # \u0412\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043c\u0430\u0441\u0441\u043e\u0432\u043e\u0439 \u0434\u043e\u043b\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432 \u0444\u043e\u0440\u043c\u0443\u043b\u0435 \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c \u0444\u043e\u0440\u043c\u0443\u043b\u044b \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e \u0432\u0435\u0449\u0435\u0441\u0442\u0432\u0430 oxygen.py -cr -mf &lt;\u0424\u041e\u0420\u041c\u0423\u041b\u0410> -mfe &lt;\u042d\u041b\u0415\u041c\u0415\u041d\u0422 \u0418\u0417 \u0424\u041e\u0420\u041c\u0423\u041b\u042b><\/code><\/pre>\n<p>Argparse \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0444\u043b\u0430\u0433\u0438, \u0438 \u0432\u043c\u0435\u0441\u0442\u043e -c -r \u043c\u043e\u0436\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c -cr.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u044f \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u043b \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u0438\u0445 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>\u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0437\u0430\u0439\u043c\u0435\u043c\u0441\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0445\u0438\u043c\u0438\u0435\u0439 \u0433\u043b\u0443\u0431\u043e\u043a\u043e. \u0421 \u0432\u0430\u043c\u0438 \u0431\u044b\u043b \u0434\u043e\u043a\u0442\u043e\u0440 \u0410\u0440\u0433\u0435\u043d\u0442\u0443\u043c, \u0432\u0441\u0435\u043c \u043f\u043e\u043a\u0430!<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/776262\/\"> https:\/\/habr.com\/ru\/articles\/776262\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><a href=\"https:\/\/habr.com\/ru\/articles\/774918\/\" rel=\"noopener noreferrer nofollow\">\u041f\u0440\u043e\u0448\u043b\u0430\u044f \u043c\u043e\u044f \u0441\u0442\u0430\u0442\u044c\u044f<\/a> \u043d\u0430\u0431\u0440\u0430\u043b\u0430 \u0445\u043e\u0440\u043e\u0448\u0438\u0439 \u043e\u0442\u043a\u043b\u0438\u043a.<\/p>\n<p>\u0418 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0440\u0435\u0448\u0438\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<p>\u0418\u0442\u0430\u043a, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u044f \u043d\u0435 \u0441\u043c\u043e\u0433\u0443 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0441\u0435, \u0447\u0442\u043e \u0445\u043e\u0442\u0435\u043b\u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0442\u043e\u0440\u044b \u0432 \u043f\u0440\u043e\u0448\u043b\u043e\u043c \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0435, \u043d\u043e \u044f \u043f\u043e\u0441\u0442\u0440\u0430\u044e\u0441\u044c \u0432\u044b\u043b\u043e\u0436\u0438\u0442\u044c\u0441\u044f, \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0443.<\/p>\n<p>\u0425\u043e\u0447\u0443 \u043d\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u0432 <a href=\"https:\/\/habr.com\/ru\/articles\/775464\/\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u044f \u0442\u0430\u043a\u0436\u0435 \u0443\u0434\u0435\u043b\u0438\u043b \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043a\u043e\u0434\u0443.<\/p>\n<p>\u041d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u044e, \u0447\u0442\u043e \u0432\u0435\u0441\u044c <a href=\"https:\/\/github.com\/OkulusDev\/Oxygen\" rel=\"noopener noreferrer nofollow\">\u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 &#8212; \u0437\u0434\u0435\u0441\u044c, \u043d\u0430 \u043c\u043e\u0435\u043c GitHub&#8217;\u0435.<\/a><\/p>\n<h2>\u0420\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433 \u043a\u043e\u0434\u0430<\/h2>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u043b \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043f\u0443\u0442\u0435\u043c \u043a\u043e\u043f\u0438\u043f\u0430\u0441\u0442\u0438\u043d\u0433\u0430 \u0438 \u0440\u0443\u0447\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e\u0431 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0445.<\/p>\n<p>\u041d\u043e \u044f \u0440\u0435\u0448\u0438\u043b, \u0447\u0442\u043e \u043b\u0443\u0447\u0448\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0433\u043e\u0442\u043e\u0432\u043e\u0433\u043e csv-\u0444\u0430\u0439\u043b\u0430 \u0441 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439 \u043e\u0431\u043e \u0432\u0441\u0435\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0445.<\/p>\n<p>\u0410 \u0442\u0430\u043a\u0436\u0435, \u0432\u043c\u0435\u0441\u0442\u043e \u043f\u0440\u044f\u043c\u043e\u0433\u043e \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f, \u044f \u0441\u043e\u0437\u0434\u0430\u044e \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f \u0441\u043f\u0438\u0441\u043e\u043a \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0441\u043a\u0430\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043f\u043e \u0440\u0430\u0437\u043d\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c.<\/p>\n<p><a href=\"https:\/\/gist.github.com\/GoodmanSciences\/c2dd862cd38f21b0ad36b8f96b4bf1ee\" rel=\"noopener noreferrer nofollow\">\u0422\u0430\u0431\u043b\u0438\u0446\u0430 \u0441 \u0445\u0438\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u0437\u0434\u0435\u0441\u044c.<\/a><\/p>\n<p>\u041d\u0430\u043c \u043d\u0430\u0434\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0444\u0430\u0439\u043b \u0441 \u0445\u0438\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438:<\/p>\n<pre><code class=\"python\">#!\/usr\/bin\/python3 # -*- coding:utf-8 -*- \"\"\" Oxygen Library --------------------------------------------------------------------------------  \u0410\u0432\u0442\u043e\u0440: Okulus Dev (aka DrArgentum)  \u041b\u0438\u0446\u0435\u043d\u0437\u0438\u044f: GNU GPL v3 --------------------------------------------------------------------------------  \u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435: \u0444\u0430\u0439\u043b \u0441 \u0445\u0438\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438  Copyright (C) 2023  Okulus Dev This program is free software: you can redistribute it and\/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program.  If not, see &lt;https:\/\/www.gnu.org\/licenses\/>. \"\"\" import csv from typing import Union   def round_to_nearest(num: int):     num = int(num + (0.5 if num > 0 else -0.5))     return num   class Element:     def __init__(self, atomic_number: int, name: str, symbol: str, atomic_mass: float,                 neutrons: int, protons: int, electrons: int, period: int, group: int,                 phase: str, radioctive: bool, natural: bool, metall: bool, nonmetall: bool,                 metalloid: bool, element_type: str):         self.atomic_number = int(atomic_number)         self.name = name         self.short_name = symbol         self.relative_atomic_mass = float(atomic_mass)         self.neutrons = int(neutrons)         self.protons = int(protons)         self.electrons = int(electrons)         self.period = int(period)         self.group = group         self.phase = phase         if natural == '':             self.natural = False         else:             self.natural = True         if radioctive == '':             self.radioctive = False         else:             self.radioctive = True         if metall == '':             self.metall = False         else:             self.metall = True         if nonmetall == '':             self.nonmetall = False         else:             self.nonmetall = True         if metalloid == '':             self.metalloid = False         else:             self.metalloid = True         if element_type == '':             self.element_type = 'Unknown'         else:             self.element_type = element_type   AVOGADRO_NUMBER = 6.02214076e23 ELEMENTS = []  # \u043f\u0443\u0442\u044c \u0434\u043e csv \u0444\u0430\u0439\u043b\u0430 with open('oxygen\/chemistry\/data\/PeriodicTable.csv', newline='') as File:     reader = csv.reader(File)     c = 0     for row in reader:         if c == 0:             c += 1             continue         # \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432\u043f\u043b\u043e\u0442\u044c \u0434\u043e \u0442\u0438\u043f\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430         # todo: \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u043e\u043b\u044f         ELEMENTS.append(Element(row[0], row[1], row[2], row[3], row[4], row[5],                                 row[6], row[7], row[8], row[9], row[10],                                 row[11], row[12], row[13], row[14], row[15]))   class MendeleevTable:     def __init__(self, elements: list) -> None:         self.elements = elements      def get_element_by_shortname(self, shortname: str) -> Union[Element, None]:         for element in self.elements:             if element.short_name == shortname:                 return element          return None      def get_element_by_name(self, name: str) -> Union[Element, None]:         for element in self.elements:             if element.name == name:                 return element          return None      def get_element_by_number(self, num: int) -> Union[Element, None]:         for element in self.elements:             if element.atomic_number == num:                 return element          return None   MendeleevTable = MendeleevTable(ELEMENTS)<\/code><\/pre>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435, \u0447\u0442\u043e \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f &#8212; \u044d\u0442\u043e \u043a\u043b\u0430\u0441\u0441 \u0445\u0438\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0444\u043e\u0440\u043c\u0443\u043b\u044b. \u0415\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0432\u0432\u0435\u043b \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u0445\u0438\u043c\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0444\u043e\u0440\u043c\u0443\u043b\u0443, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u0430\u0445\u0430\u0440\u043e\u0437\u0443 \u0438\u043b\u0438 \u0432\u043e\u0434\u0443, \u0442\u043e \u043c\u044b \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e\u0431 \u044d\u0442\u043e\u043c<\/p>\n<pre><code class=\"python\">\"\"\" Copyright (C) 2023  Okulus Dev This program is free software: you can redistribute it and\/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program.  If not, see &lt;https:\/\/www.gnu.org\/licenses\/>. \"\"\" # \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u043f\u043e\u0440\u0442 \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440\u0430 \u043c\u043e\u043b\u0435\u043a\u0443\u043b\u044f\u0440\u043d\u043e\u0439 \u043c\u0430\u0441\u0441\u044b, \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u0437\u0434\u0435\u0441\u044c \u0432\u0441\u0435 \u0435\u0441\u0442\u044c # \u043d\u043e \u0442.\u043a. \u044d\u0442\u043e \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b, \u0442\u043e \u044f \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u0432\u044b \u0441\u0430\u043c\u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0439\u0442\u0435 \u0438\u043b\u0438 \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u0435 \u043a\u043e\u0434 # (\u0434\u0430\u0431\u044b \u043d\u0435 \u0437\u0430\u043f\u0443\u0442\u0430\u0442\u044c \u0432\u0430\u0441)   class ChemicalFormula:     \"\"\"\u041a\u043b\u0430\u0441\u0441 \u0445\u0438\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0444\u043e\u0440\u043c\u0443\u043b\u044b\"\"\"     def __init__(self, elements: dict, formula: str,                  name: str, molecular_mass: float=None):         self.elements = elements         self.formula = formula         if molecular_mass is not None:             self.molecular_mass = molecular_mass         else:             self.molucular_mass = calculate_relative_molecular_mass(formula, False)         self.name = name   # \u0425\u0438\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0444\u043e\u0440\u043c\u0443\u043b\u044b CHEMICAL_FORMULAS = {     'H2O': ChemicalFormula({('H', 2), ('O', 1)}, \"H2O\", '\u0412\u043e\u0434\u0430', None),     'C12H22O11': ChemicalFormula({('C', 12), ('H', 22), ('O', 11)},                                  \"C12H22O11\", '\u0421\u0430\u0445\u0430\u0440\u043e\u0437\u0430 (\u0441\u0430\u0445\u0430\u0440)', None) }   def read_formula(formula: str):     \"\"\"\u0427\u0438\u0442\u0430\u0435\u043c \u0444\u043e\u0440\u043c\u0443\u043b\u0443 \u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0435\u0435, \u0435\u0441\u043b\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u0430\u043a\u043e\u0432\u0430\u044f\"\"\"     if formula in CHEMICAL_FORMULAS:         print(f'\u0424\u043e\u0440\u043c\u0443\u043b\u0430 {formula} \u044d\u0442\u043e - {CHEMICAL_FORMULAS[formula].name}')         elements_in_formula = []          for el in CHEMICAL_FORMULAS[formula].elements:             elements_in_formula.append(f\"{el[1]} {MendeleevTable.get_element_by_shortname(el[0]).name}\")          elements_in_formula_str = \", \".join(elements_in_formula)         print(f'{CHEMICAL_FORMULAS[formula].name} \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 {elements_in_formula_str}')<\/code><\/pre>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043a\u043e\u0434.<\/p>\n<pre><code class=\"python\">#!venv\/bin\/python3 \"\"\" Oxygen Library --------------------------------------------------------------------------------  \u0410\u0432\u0442\u043e\u0440: Okulus Dev (aka DrArgentum)  \u041b\u0438\u0446\u0435\u043d\u0437\u0438\u044f: GNU GPL v3 --------------------------------------------------------------------------------  \u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435: \u0411\u0430\u0437\u043e\u0432\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0445\u0438\u043c\u0438\u0438 \u0432 \u0432\u0430\u0448\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445   \u041f\u0435\u0440\u0435\u0447\u0435\u043d\u044c:    1. \u041f\u0430\u0440\u0441\u0438\u043d\u0433 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0438\u0437 \u0444\u043e\u0440\u043c\u0443\u043b\u044b    2. \u0412\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043c\u043e\u043b\u0435\u043a\u0443\u043b\u044f\u0440\u043d\u043e\u0439 \u043c\u0430\u0441\u0441\u044b    3. \u0412\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043c\u0430\u0441\u0441\u043e\u0432\u043e\u0439 \u0434\u043e\u043b\u0438  Copyright (C) 2023  Okulus Dev This program is free software: you can redistribute it and\/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program.  If not, see &lt;https:\/\/www.gnu.org\/licenses\/>. \"\"\" import re from collections import Counter # \u0437\u0434\u0435\u0441\u044c \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u0438\u043c\u043f\u043e\u0440\u0442 \u0438\u043b\u0438 \u0432\u0441\u0442\u0430\u0432\u043a\u0430 \u043a\u043e\u0434\u0430 \u0445\u0438\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430   def repl(m):     return m[1] * int(m[2] if m[2] else 1)   def is_balanced(text, brackets=\"\u3008\u3009()[]{}\"):     opening, closing = brackets[::2], brackets[1::2]     stack = []     for character in text:         if character in opening:             stack.append(opening.index(character))         elif character in closing:             if stack and stack[-1] == closing.index(character):                 stack.pop()               else:                 return False     return (not stack)     def parse_molecule(formula: str) -> dict:     \"\"\"\u041f\u0430\u0440\u0441\u0438\u043d\u0433 \u043c\u043e\u043b\u0435\u043a\u0443\u043b\u044b\"\"\"     if not is_balanced(formula):         raise ValueError(f\"Brackets in {formula} is not balanced\")         sys.exit()          while '(' in formula:         formula = re.sub(r'\\((\\w*)\\)(\\d*)', repl, formula)     while '[' in formula:         formula = re.sub(r'\\[(\\w*)\\](\\d*)', repl, formula)     formula = re.sub(r'([A-Z][a-z]?)(\\d*)', repl, formula)     formula_dict = Counter(re.findall('[A-Z][a-z]*', formula))      return formula_dict   def get_element_mass(element: str):     \"\"\"\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043c\u0430\u0441\u0441\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043f\u043e \u0435\u0433\u043e \u0445\u0438\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u043c\u0443 \u0437\u043d\u0430\u0447\u043a\u0443\"\"\"     try:         return MendeleevTable.get_element_by_shortname(element).relative_atomic_mass     except:         raise ValueError(f\"Element {element} does not exists. Try other!\")         sys.exit()  def calculate_mass_fraction_of_element(formula: str, element: str):     \"\"\"\u0412\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u043c\u0430\u0441\u0441\u043e\u0432\u0443\u044e \u0434\u043e\u043b\u044e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432 \u0444\u043e\u0440\u043c\u0443\u043b\u0435\"\"\"     formula = parse_molecule(formula)     mass_fraction = 0     mass = 0      for i in formula.items():         mass += get_element_mass(i[0]) * i[1]      for i in formula.items():         if MendeleevTable.get_element_by_shortname(i[0]).short_name ==<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-361146","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/361146","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=361146"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/361146\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=361146"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=361146"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=361146"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}