# PyOrganic **Repository Path**: NKID00/PyOrganic ## Basic Information - **Project Name**: PyOrganic - **Description**: 一个使用类来描述有机化合物结构的Python库。 - **Primary Language**: Python - **License**: MIT - **Default Branch**: master - **Homepage**: https://gitee.com/NKID00/PyOrganic - **GVP Project**: No ## Statistics - **Stars**: 3 - **Forks**: 0 - **Created**: 2020-05-03 - **Last Updated**: 2023-04-26 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # PyOrganic ## 介绍 > 一个使用类来描述有机化合物结构的Python库。 ## 架构 > **Compound**:描述化合物 > > **Atom**(抽象类) -> **Carbon**, **Hydrogen**:描述原子 > > **Bond**(抽象类) -> **SingleBond**, **DoubleBond**, **TripleBond**:描述键 ## 示例 ```python from PyOrganic import * # 导入 PyOrganic Methane = Compound() # 定义化合物甲烷 C1 = Carbon(Methane) # 定义5个原子 H1 = Hydrogen(Methane) H2 = Hydrogen(Methane) H3 = Hydrogen(Methane) H4 = Hydrogen(Methane) SingleBond(C1, H1) # 连接原子 SingleBond(C1, H2) SingleBond(C1, H3) SingleBond(C1, H4) Methane.entry_atom = C1 # 设置根原子 print(Methane.chemical_formula) # 输出化学式 -> CH₄ ``` ## 文档 ## *class* **Compound** > 化合物 ## **方法** ### *def* **\_\_init\_\_**(self) > 构造化合物 ## **属性** ### **entry_atom**: Atom > 访问该化合物的入口点 ## **只读属性** ### **atoms**: list[Atom] > 该化合物所拥有的原子 ### **chemical\_formula**: str > 化学式 ### **name**: str > 系统命名法下的名称(待补)
## *class* **Atom** > 原子 ## **方法** ### *def* **\_\_init\_\_**(self, **name**: str, **symbol**: str, **max_bonds**: int, **compound**: Compound) > 构造原子 - **name** : 原子名称 - **symbol** : 元素符号 - **max\_bonds** : 最大能连接的键数 - **compound** : 从属的化合物 ### *def* **set\_bond**(self, **bond**: Bond) > 在该原子上单方面连接新的键 - **bond** : 新连接的键 ### *def* **spread**(self, **atoms**: Iterable[Atoms]) > 递归寻找化合物中所有原子 - **atoms** : 由所有原子组成的列表 ## **只读属性** ### **bonds**: list[Bond] > 获得原子上所连的键的集合 ### **compound**: Compound > 该原子所属化合物 ### **max\_bonds**: int > 最大可连的键的数量 ### **name**: str > 原子名称 ### **next\_atoms**: list[Atom] > 与该原子相连的原子 ### **rest\_bonds\_value**: int > 剩余可连的键的数量 ### **symbol**: str > 元素符号
## *class* **Carbon**(Atom) > 碳原子 ## **方法** ### **\_\_init\_\_**(self, **compound**: Compound) => Atom.\_\_init\_\_('碳', 'C', 4, compound) > 构造碳原子 - **compound** : 从属的化合物
## *class* **Hydrogen**(Atom) > 氢原子 ## **方法** ### **\_\_init\_\_**(self, **compound**: Compound) => Atom.\_\_init\_\_('氢', 'H', 1, compound) > 构造氢原子 - **compound** : 从属的化合物
## *class* **Bond** > 键 ## **方法** ### *def* **\_\_init\_\_**(self, **left\_atom**: Atom, **right\_atom**: Atom, **value**: int, **name**: str): > 构造键 - **left\_atom** : 键左侧的原子 - **right\_atom** : 键右侧的原子 - **value** : 键值(共用电子对数),单键为1,双键为2,叁键为3 - **name** : 键名 ## **只读属性** ### **left\_atom**: Atom > 键左边连的原子 ### **right\_atom**: Atom > 键右边连的原子 ### **value**: int > 键值(共用电子对数),单键为1,双键为2,叁键为3 ### **name**: str > 键名
## *class* **SingleBond**(Bond) ## **方法** ### *def* **\_\_init\_\_**(**left\_atom**: Atom, **right\_atom**: Atom) => Bond.\_\_init\_\_(left*atom, right*atom, 1, '单键') > 构造单键 - **left\_atom** : 键左侧的原子 - **right\_atom** : 键右侧的原子
## *class* **DoubleBond**(Bond) ## **方法** ### *def* **\_\_init\_\_**(**left\_atom**: Atom, **right\_atom**: Atom) => Bond.\_\_init\_\_(left*atom, right*atom, 2, '双键') > 构造双键 - **left\_atom** : 键左侧的原子 - **right\_atom** : 键右侧的原子
## *class* **TripleBond**(Bond) ## **方法** ### *def* **\_\_init\_\_**(**left\_atom**: Atom, **right\_atom**: Atom) => Bond.\_\_init\_\_(left*atom, right*atom, 3, '叁键') > 构造叁键 - **left\_atom** : 键左侧的原子 - **right\_atom** : 键右侧的原子
## *class* **NotTheSameCompoundError**(Exception) > 当不同化合物的原子试图成键时抛出
## *class* **NotEnoughBondsError**(Exception) > 当剩余可连的键不足的原子试图成键时抛出
## 贡献者 - ZZH - NKID00