-
Notifications
You must be signed in to change notification settings - Fork 2
/
markinchi2inchi.py
executable file
·55 lines (48 loc) · 1.58 KB
/
markinchi2inchi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#################################################################
#
# source activate my-rdkit-env
#
################################################################
from rdkit import Chem
def run(inchiplus, smiles_core):
#print("=============")
#print(inchiplus)
#print(smiles_core)
inchiplus_item = inchiplus.pop(0)
grouplist=inchiplus_item.split("!")
for substituent in grouplist:
if substituent == "H":
substituent = ""
new_smiles=smiles_core.replace("[TeH]", substituent, 1)
if new_smiles.find("()") >= 0:
new_smiles=smiles_core.replace("[TeH]", substituent, 1).replace("()","")
if len(inchiplus) == 0:
new_inchi=Chem.MolToInchi(Chem.MolFromSmiles(new_smiles))
#print(new_smiles)
print(new_inchi)
else:
#print(inchiplus)
#print(new_smiles)
new_inchiplus = inchiplus.copy()
run(new_inchiplus, new_smiles)
#print("back from recursion")
#print(substituent,new_smiles,inchiplus)
return
#if True:# __name__=="__main__":
if __name__=="__main__":
from sys import argv
if argv[1].find("Te") == -1:
print("No tellurium")
elif argv[1].find("<>") == -1:
print("No substituents")
else:
inchiplus = argv[1].split("<>")
#grouplist = inchiplus[1].split("!")
#run(inchiplus, grouplist)
inchiplus_item = inchiplus.pop(0)
molfrominchi = Chem.rdinchi.InchiToMol(inchiplus_item)
smiles_core=Chem.MolToSmiles(molfrominchi[0])
#print(inchiplus_item)
#print(inchiplus)
#print(smiles_core)
run(inchiplus, smiles_core)