Skip to content

Commit 5edc947

Browse files
committed
add molecule maker
1 parent e2bdbbe commit 5edc947

9 files changed

Lines changed: 403 additions & 73 deletions

File tree

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"python.analysis.typeCheckingMode": "basic"
2+
"python.analysis.typeCheckingMode": "basic",
3+
"cSpell.words": [
4+
"GRAPHER"
5+
]
36
}

notebook/combine.ipynb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
},
2828
{
2929
"cell_type": "code",
30-
"execution_count": 37,
30+
"execution_count": 2,
3131
"metadata": {},
3232
"outputs": [
3333
{
@@ -90,7 +90,7 @@
9090
},
9191
{
9292
"cell_type": "code",
93-
"execution_count": 39,
93+
"execution_count": 3,
9494
"metadata": {},
9595
"outputs": [],
9696
"source": [
@@ -119,7 +119,7 @@
119119
},
120120
{
121121
"cell_type": "code",
122-
"execution_count": 40,
122+
"execution_count": 4,
123123
"metadata": {},
124124
"outputs": [
125125
{
@@ -178,7 +178,7 @@
178178
},
179179
{
180180
"cell_type": "code",
181-
"execution_count": 18,
181+
"execution_count": 5,
182182
"metadata": {},
183183
"outputs": [],
184184
"source": [
@@ -199,7 +199,7 @@
199199
},
200200
{
201201
"cell_type": "code",
202-
"execution_count": 8,
202+
"execution_count": 6,
203203
"metadata": {},
204204
"outputs": [],
205205
"source": [
@@ -261,7 +261,7 @@
261261
},
262262
{
263263
"cell_type": "code",
264-
"execution_count": null,
264+
"execution_count": 7,
265265
"metadata": {},
266266
"outputs": [],
267267
"source": [
@@ -331,7 +331,7 @@
331331
},
332332
{
333333
"cell_type": "code",
334-
"execution_count": 30,
334+
"execution_count": 8,
335335
"metadata": {},
336336
"outputs": [
337337
{
@@ -371,7 +371,7 @@
371371
},
372372
{
373373
"cell_type": "code",
374-
"execution_count": 43,
374+
"execution_count": 9,
375375
"metadata": {},
376376
"outputs": [],
377377
"source": [
@@ -523,7 +523,7 @@
523523
},
524524
{
525525
"cell_type": "code",
526-
"execution_count": 44,
526+
"execution_count": 10,
527527
"metadata": {},
528528
"outputs": [
529529
{

pyMolinfo/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from .app import (main, __version__, g3d, g3d_by_inchi, check_functional_group, create_graph, compound, compound_by_cid, compound_by_inchi, create_custom_functional_groups, count_functional_group, __author__)
1+
from .app import (main, __version__, g3d, g3d_by_inchi, check_functional_group, create_graph, compound, compound_by_cid,
2+
compound_by_inchi, create_custom_functional_groups, count_functional_group, __author__, create_molecule_graph)
23

34
__all__ = ['main', '__version__', '__author__', 'g3d',
4-
'g3d_by_inchi', 'check_functional_group', 'create_graph', 'compound', 'compound_by_cid', 'compound_by_inchi', 'create_custom_functional_groups', 'count_functional_group']
5+
'g3d_by_inchi', 'check_functional_group', 'create_graph', 'compound', 'compound_by_cid', 'compound_by_inchi', 'create_custom_functional_groups', 'count_functional_group', 'create_molecule_graph']

pyMolinfo/app.py

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from .config import __version__
1313
from .config import __description__
1414
from .config import __author__
15-
from .docs import MolParser, Compound, CustomChemGraph, Utility
15+
from .docs import MolParser, Compound, CustomChemGraph, Utility, Molecule
1616

1717

1818
def main():
@@ -400,44 +400,57 @@ def create_custom_functional_groups(functional_groups: Union[Dict[str, List[str]
400400
raise Exception(f'creating custom functional group is failed! {e}')
401401

402402

403-
def combine_custom_functional_groups(functional_groups: Union[Dict[str, List[str]], List[Dict[str, List[str]]], Path, str]) -> CustomChemGraph:
403+
def create_molecule_graph(molecule_src: Union[Dict[str, List[str]], Path], molecule_name: str = 'MainChain') -> CustomChemGraph:
404404
'''
405-
Combines custom functional groups based on the following example.
405+
Make a molecule graph from custom functional groups based on the following example.
406406
407407
Parameters
408408
----------
409-
functional_groups : list[dict] or dict
410-
functional group
409+
molecule_src : Dict[str, List[str]] | str
410+
molecule source
411+
molecule_name : str
412+
molecule name (default 'MainChain')
411413
412414
Returns
413415
-------
414-
custom_functional_groups : list[dict]
415-
a list of all custom functional group
416+
molecule : Molecule
417+
molecule object
416418
417419
Examples
418420
--------
419421
```python
420-
# fg1: CH2-O
421-
# fg2: CH2CHO
422-
# List of custom functional groups
423-
custom_functional_group = [
424-
{'fg1': ["C1-H1","C1-H2","C1-O1"]},
425-
{'fg2': ["fg1-H1","C1-H2","C1-C2","C2-H3","C2-O2"]}
426-
]
427-
428-
# Dict of custom functional groups
429-
custom_functional_group = {
430-
'fg1': ["C1-H1","C1-H2","C1-O1"],
431-
'fg2': ["fg1-H1","C1-H2","C1-C2","C2-H3","C2-O2"]
422+
# molecule source
423+
molecule_src = {
424+
'MainChain': ["C1-C2","C2-C3","C3*{Chain1}","C3-C4","C4*{Chain2}","C4-C5","C5-C6"],
425+
'Chain1': ["C1=C2","C2-C3","C3=*"],
426+
'Chain2' : ["*-C1","C1=C2","C2-XX3"]
432427
}
433428
```
429+
430+
Notes
431+
-----
432+
- `*` is a connection point
433+
- `{}` is a reference to another chain
434+
- C3*{Chain1} means C3 is connected to Chain1 from C3=*
435+
- Bond index starts from 1 in all chains
436+
- Bond type: single bond (-), double bond (=), triple bond (#)
434437
'''
435438
try:
436-
# create custom functional group
437-
CustomChemGraphC = create_custom_functional_groups(functional_groups)
439+
# check format
440+
if isinstance(molecule_src, (str, Path)):
441+
# check is a file yml
442+
_mol_src = Utility.load_custom_functional_group(
443+
molecule_src)
444+
445+
# init molecule
446+
MoleculeC = Molecule(molecule_src, molecule_name)
447+
448+
# build molecule
449+
_, _, _, molecule = MoleculeC.build()
450+
451+
# custom chem graph
452+
CustomChemGraphC = CustomChemGraph([molecule])
438453

439-
# combine custom functional groups
440-
CustomChemGraphC.combine_custom_graph()
441454
# res
442455
return CustomChemGraphC
443456
except Exception as e:

pyMolinfo/docs/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
from .netwrok import Network
44
from .customchemgraph import CustomChemGraph
55
from .utility import Utility
6+
from .molecule import Molecule

pyMolinfo/docs/graphutils.py

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)