Skip to content

Commit a5401a0

Browse files
committed
Tox format
1 parent 056af27 commit a5401a0

File tree

1 file changed

+60
-28
lines changed

1 file changed

+60
-28
lines changed

bluephos/modules/octahedral_embed/__init__.py

Lines changed: 60 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,53 @@
11
import os.path
2+
23
from rdkit import Chem
3-
from rdkit.Chem.rdchem import RWMol, Conformer
4-
from rdkit.Chem.rdmolfiles import MolFromMol2File, MolFromSmarts
54
from rdkit.Chem.AllChem import ConstrainedEmbed
5+
from rdkit.Chem.rdchem import Conformer, RWMol
66
from rdkit.Chem.rdChemReactions import ReactionFromSmarts
7+
from rdkit.Chem.rdmolfiles import MolFromMol2File, MolFromSmarts
78
from rdkit.Chem.rdmolops import RemoveStereochemistry
89

9-
def make_bonds_dative(mol, target_elem = "Ir"):
10+
11+
def make_bonds_dative(mol, target_elem="Ir"):
1012
editable_mol = RWMol(mol)
1113

1214
# If you don't make a list, it loops infinitely over the bonds it's creating
1315
for bond in list(editable_mol.GetBonds()):
1416
iridium = None
1517
nitrogen = None
1618
carbene = None
17-
if bond.GetBeginAtom().GetSymbol() == target_elem and \
18-
bond.GetEndAtom().GetSymbol() in ["N", "P"] and \
19-
bond.GetEndAtom().GetFormalCharge() == 1:
19+
if (
20+
bond.GetBeginAtom().GetSymbol() == target_elem
21+
and bond.GetEndAtom().GetSymbol() in ["N", "P"]
22+
and bond.GetEndAtom().GetFormalCharge() == 1
23+
):
2024
iridium = bond.GetBeginAtom()
2125
nitrogen = bond.GetEndAtom()
2226
start_idx = bond.GetEndAtomIdx()
2327
end_idx = bond.GetBeginAtomIdx()
24-
elif bond.GetEndAtom().GetSymbol() == target_elem and \
25-
bond.GetBeginAtom().GetSymbol() in ["N", "P"] and \
26-
bond.GetBeginAtom().GetFormalCharge() == 1:
28+
elif (
29+
bond.GetEndAtom().GetSymbol() == target_elem
30+
and bond.GetBeginAtom().GetSymbol() in ["N", "P"]
31+
and bond.GetBeginAtom().GetFormalCharge() == 1
32+
):
2733
iridium = bond.GetEndAtom()
2834
nitrogen = bond.GetBeginAtom()
2935
start_idx = bond.GetBeginAtomIdx()
3036
end_idx = bond.GetEndAtomIdx()
31-
if bond.GetBeginAtom().GetSymbol() == target_elem and \
32-
bond.GetEndAtom().GetSymbol() == "C" and \
33-
bond.GetEndAtom().GetTotalValence() == 3:
37+
if (
38+
bond.GetBeginAtom().GetSymbol() == target_elem
39+
and bond.GetEndAtom().GetSymbol() == "C"
40+
and bond.GetEndAtom().GetTotalValence() == 3
41+
):
3442
iridium = bond.GetBeginAtom()
3543
carbene = bond.GetEndAtom()
3644
start_idx = bond.GetEndAtomIdx()
3745
end_idx = bond.GetBeginAtomIdx()
38-
elif bond.GetEndAtom().GetSymbol() == target_elem and \
39-
bond.GetBeginAtom().GetSymbol() == "C" and \
40-
bond.GetBeginAtom().GetTotalValence() == 3:
46+
elif (
47+
bond.GetEndAtom().GetSymbol() == target_elem
48+
and bond.GetBeginAtom().GetSymbol() == "C"
49+
and bond.GetBeginAtom().GetTotalValence() == 3
50+
):
4151
iridium = bond.GetEndAtom()
4252
carbene = bond.GetBeginAtom()
4353
start_idx = bond.GetBeginAtomIdx()
@@ -56,17 +66,19 @@ def make_bonds_dative(mol, target_elem = "Ir"):
5666

5767
return outmol
5868

59-
def transfer_conformation(mol, substruct, conformer = 0):
60-
'''Given a molecule, and a second molecule which is a substructure of the
69+
70+
def transfer_conformation(mol, substruct, conformer=0):
71+
"""Given a molecule, and a second molecule which is a substructure of the
6172
first, assign coordinates to the substructure based on the matching part of
62-
the original molecule'''
73+
the original molecule"""
6374
match = mol.GetSubstructMatch(substruct)
6475
substruct_conformation = Conformer(substruct.GetNumAtoms())
6576
for i, index in enumerate(match):
6677
point = mol.GetConformer(conformer).GetAtomPosition(index)
6778
substruct_conformation.SetAtomPosition(i, point)
6879
substruct.AddConformer(substruct_conformation)
6980

81+
7082
fac = make_bonds_dative(MolFromMol2File(os.path.join(__path__[0], "OHUZEW.mol2")))
7183
RemoveStereochemistry(fac)
7284
mer = make_bonds_dative(MolFromMol2File(os.path.join(__path__[0], "OHUZIA.mol2")))
@@ -79,6 +91,7 @@ def transfer_conformation(mol, substruct, conformer = 0):
7991
carbene_mer = make_bonds_dative(MolFromMol2File(os.path.join(__path__[0], "MAXYOA.mol2")))
8092
RemoveStereochemistry(carbene_mer)
8193

94+
8295
# Extract skeletons of a molecule based on a template, keeping coordinates
8396
# Multiple skeletons because I don't know how to do wildcards
8497
def skeleton(template, mol):
@@ -96,50 +109,69 @@ def skeleton(template, mol):
96109
skeleton_mol = editable_mol.GetMol()
97110
return skeleton_mol
98111

112+
99113
fac_skeleton = skeleton(template, fac)
100114
mer_skeleton = skeleton(template, mer)
101115

102116
# Making the carbene skeletons in a completely different way
103117
# I probably am going to want to do this for all of them
104-
carbene_skeleton_smarts = "[Ir]135(<-[CH0](~N(~*)~*~2)~N(~*~2)~c~c~1)(<-[CH0](~N(~*)~*~4)~N(~*~4)~c~c~3)(<-[CH0](~N(~*)~*~6)~N(~*~6)~c~c~5)"
118+
carbene_skeleton_smarts = (
119+
"[Ir]135(<-[CH0](~N(~*)~*~2)~N(~*~2)~c~c~1)(<-[CH0](~N(~*)~*~4)~N(~*~4)~c~c~3)(<-[CH0](~N(~*)~*~6)~N(~*~6)~c~c~5)"
120+
)
105121
carbene_fac_skeleton = MolFromSmarts(carbene_skeleton_smarts)
106122
transfer_conformation(carbene_fac, carbene_fac_skeleton)
107123
carbene_mer_skeleton = MolFromSmarts(carbene_skeleton_smarts)
108124
transfer_conformation(carbene_mer, carbene_mer_skeleton)
109125

126+
110127
def run_three_times(mol, reaction):
111128
for i in range(3):
112129
mol = reaction.RunReactants([mol])[0][0]
113130
return mol
131+
132+
114133
reactions = [
115134
ReactionFromSmarts("[Ir:1]1<-[n:2]:[n:3]~[c:4]:[c:5]~1>>[Ir:1]1<-[n:2]:[c:3]~[n:4]:[c:5]~1"),
116135
ReactionFromSmarts("[Ir:1]1<-[n:2]:[n:3]~[c:4]:[c:5]~1>>[Ir:1]1<-[n:2]:[n:3]~[n:4]:[c:5]~1"),
117-
ReactionFromSmarts("[Ir:1]1<-[n:2]:[n:3]~[c:4]:[c:5]~1>>[Ir:1]1<-[n:2]:[c:3]~[c:4]:[c:5]~1")
136+
ReactionFromSmarts("[Ir:1]1<-[n:2]:[n:3]~[c:4]:[c:5]~1>>[Ir:1]1<-[n:2]:[c:3]~[c:4]:[c:5]~1"),
118137
]
119-
fac_skeletons = [fac_skeleton] + [run_three_times(fac_skeleton, reaction) for reaction in reactions] + [carbene_fac_skeleton]
120-
mer_skeletons = [mer_skeleton] + [run_three_times(mer_skeleton, reaction) for reaction in reactions] + [carbene_mer_skeleton]
138+
fac_skeletons = (
139+
[fac_skeleton] + [run_three_times(fac_skeleton, reaction) for reaction in reactions] + [carbene_fac_skeleton]
140+
)
141+
mer_skeletons = (
142+
[mer_skeleton] + [run_three_times(mer_skeleton, reaction) for reaction in reactions] + [carbene_mer_skeleton]
143+
)
121144

122145
# Skeletons for tridentate carbenes
123146
# I may have to remake these later if I want to control the isomers
124147
# For now I think it doesn't matter because all the carbene ligands are symmetric?
125148
# For homoleptic:
126149
biplet = make_bonds_dative(MolFromMol2File(os.path.join(__path__[0], "BIPLET.mol2")))
127-
biplet_skeleton = MolFromSmarts('[Ir]1234(~[#6](~[#7](~[#6])~[#6])~[#7]~c~c~1~c~[#7]~[#6](~[#7](~[#6])~[#6])~2)~[#6](~[#7](~[#6])~[#6])~[#7]~c~c~3~c~[#7]~[#6](~[#7](~[#6])~[#6])~4')
150+
biplet_skeleton = MolFromSmarts(
151+
"[Ir]1234(~[#6](~[#7](~[#6])~[#6])~[#7]~c~c~1~c~[#7]~[#6](~[#7](~[#6])~[#6])~2)~[#6](~[#7](~[#6])~[#6])~[#7]~c~c~3~c~[#7]~[#6](~[#7](~[#6])~[#6])~4"
152+
)
128153
transfer_conformation(biplet, biplet_skeleton)
129154
# For heteroleptic, three with counterligands of different size
130155
soynom = make_bonds_dative(MolFromMol2File(os.path.join(__path__[0], "SOYNOM.mol2")))
131156
RemoveStereochemistry(soynom)
132-
soynom_skeleton = MolFromSmarts('[Ir]1234(~*~*~*~*~1~*~*~*~2)~[#6](~[#7](~[#6])~[#6])~[#7]~c~c~3~c~[#7]~[#6](~[#7](~[#6])~[#6])~4')
157+
soynom_skeleton = MolFromSmarts(
158+
"[Ir]1234(~*~*~*~*~1~*~*~*~2)~[#6](~[#7](~[#6])~[#6])~[#7]~c~c~3~c~[#7]~[#6](~[#7](~[#6])~[#6])~4"
159+
)
133160
transfer_conformation(soynom, soynom_skeleton)
134161
uyokur = make_bonds_dative(MolFromMol2File(os.path.join(__path__[0], "UYOKUR.mol2")))
135-
uyokur_skeleton = MolFromSmarts('[Ir]1234(~*~*~*~*~*~1~*~*~*~2)~[#6](~[#7](~[#6])~[#6])~[#7]~c~c~3~c~[#7]~[#6](~[#7](~[#6])~[#6])~4')
162+
uyokur_skeleton = MolFromSmarts(
163+
"[Ir]1234(~*~*~*~*~*~1~*~*~*~2)~[#6](~[#7](~[#6])~[#6])~[#7]~c~c~3~c~[#7]~[#6](~[#7](~[#6])~[#6])~4"
164+
)
136165
transfer_conformation(uyokur, uyokur_skeleton)
137166
egufiz = make_bonds_dative(MolFromMol2File(os.path.join(__path__[0], "EGUFIZ.mol2")))
138-
egufiz_skeleton = MolFromSmarts('[Ir]1234(~*~*~*~*~*~1~*~*~*~*~2)~[#6](~[#7](~[#6])~[#6])~[#7]~c~c~3~c~[#7]~[#6](~[#7](~[#6])~[#6])~4')
167+
egufiz_skeleton = MolFromSmarts(
168+
"[Ir]1234(~*~*~*~*~*~1~*~*~*~*~2)~[#6](~[#7](~[#6])~[#6])~[#7]~c~c~3~c~[#7]~[#6](~[#7](~[#6])~[#6])~4"
169+
)
139170
transfer_conformation(egufiz, egufiz_skeleton)
140171
# Homoleptic has to go first, since a later pattern can cover it
141172
tridentate_skeletons = [biplet_skeleton, soynom_skeleton, uyokur_skeleton, egufiz_skeleton]
142173

174+
143175
def octahedral_embed(mol, isomer):
144176
# Needed for some of the mol2 files I got from CSD
145177
# Will not be able to embed with stereochemistry
@@ -151,7 +183,7 @@ def octahedral_embed(mol, isomer):
151183
elif isomer == "tridentate":
152184
skeletons = tridentate_skeletons
153185
else:
154-
raise ValueError(f"Isomer should be \"mer\" or \"fac\", given {isomer}")
186+
raise ValueError(f'Isomer should be "mer" or "fac", given {isomer}')
155187
finished = False
156188
for skeleton in skeletons:
157189
if len(mol.GetSubstructMatch(skeleton)) > 0:
@@ -160,7 +192,7 @@ def octahedral_embed(mol, isomer):
160192
# with a small template the imidazole is hroribly twisted, probably
161193
# because it thinks the atoms are aliphatic. Ignoring smoothing
162194
# failures with the large template, it works
163-
ConstrainedEmbed(mol, skeleton, ignoreSmoothingFailures = True)
195+
ConstrainedEmbed(mol, skeleton, ignoreSmoothingFailures=True)
164196
finished = True
165197
if not finished:
166198
raise ValueError("Doesn't match templates")

0 commit comments

Comments
 (0)