Skip to content

Commit f30cce0

Browse files
committed
fixed size_threshold check
1 parent ee6971e commit f30cce0

File tree

2 files changed

+39
-20
lines changed

2 files changed

+39
-20
lines changed

rmgpy/molecule/fragment.py

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -945,8 +945,7 @@ def sliceitup_arom(self, molecule, size_threshold=5):
945945
# mol_set contains new set of fragments
946946
mol_set = Chem.GetMolFrags(new_mol, asMols=True)
947947
# check all fragments' size
948-
frag_sizes = [sum(1 for atom in mol.GetAtoms() if atom.GetAtomicNum() == 6) for mol in mol_set]
949-
if all(x >= size_threshold for x in frag_sizes):
948+
if all(sum(1 for atom in mol.GetAtoms() if atom.GetAtomicNum() == 6) >= size_threshold for mol in mol_set):
950949
if len(mol_set) == 2:
951950
frag1 = Chem.MolToSmiles(mol_set[0])
952951
frag2 = Chem.MolToSmiles(mol_set[1])
@@ -1090,27 +1089,47 @@ def sliceitup_aliph(self, molecule, size_threshold=5):
10901089
# mol_set contains new set of fragments
10911090
mol_set = Chem.GetMolFrags(new_mol, asMols=True)
10921091
# check all fragments' size
1093-
if all(
1094-
sum(1 for atom in mol.GetAtoms() if atom.GetAtomicNum() == 6)
1095-
>= size_threshold
1096-
for mol in mol_set
1097-
):
1098-
# replace * at cutting position with cutting label
1099-
for ind, rdmol in enumerate(mol_set):
1100-
frag = Chem.MolToSmiles(rdmol)
1101-
if len(mol_set) > 2: # means it cut into 3 fragments
1092+
if all(sum(1 for atom in mol.GetAtoms() if atom.GetAtomicNum() == 6) >= size_threshold for mol in mol_set):
1093+
if len(mol_set) == 2:
1094+
frag1 = Chem.MolToSmiles(mol_set[0])
1095+
frag2 = Chem.MolToSmiles(mol_set[1])
1096+
1097+
frag1_R = frag1.count("Na")
1098+
frag1_L = frag1.count("K")
1099+
frag2_R = frag2.count("Na")
1100+
frag2_L = frag2.count("K")
1101+
1102+
if frag1_R > frag2_R and frag1_L <= frag2_L:
1103+
frag1_smi = frag1.replace("*", "L")
1104+
frag2_smi = frag2.replace("*", "R")
1105+
elif frag1_L > frag2_L and frag1_R <= frag2_R:
1106+
frag1_smi = frag1.replace("*", "R")
1107+
frag2_smi = frag2.replace("*", "L")
1108+
elif frag2_L > frag1_L and frag2_R <= frag1_R:
1109+
frag1_smi = frag1.replace("*", "R")
1110+
frag2_smi = frag2.replace("*", "L")
1111+
elif frag2_R > frag1_R and frag2_L <= frag1_L:
1112+
frag1_smi = frag1.replace("*", "R")
1113+
frag2_smi = frag2.replace("*", "L")
1114+
elif randint(0,1)==1:
1115+
frag1_smi = frag1.replace("*", "L")
1116+
frag2_smi = frag2.replace("*", "R")
1117+
else:
1118+
frag1_smi = frag1.replace("*", "R")
1119+
frag2_smi = frag2.replace("*", "L")
1120+
1121+
frag_list = [frag1_smi, frag2_smi]
1122+
1123+
elif len(mol_set) > 2: # means it cut into 3 fragments
1124+
frag_list = []
1125+
for ind, rdmol in enumerate(mol_set):
1126+
frag = Chem.MolToSmiles(rdmol)
11021127
if frag.count("*") > 1:
1103-
# replace both with R
1104-
frag_smi = frag.replace("*", "R")
1105-
else:
1106-
frag_smi = frag.replace("*", "L")
1107-
else: # means it only cut once, generate 2 fragments
1108-
if ind == 0:
11091128
frag_smi = frag.replace("*", "R")
11101129
else:
11111130
frag_smi = frag.replace("*", "L")
1112-
frag_list.append(frag_smi)
1113-
break
1131+
frag_list.append(frag_smi)
1132+
break
11141133
else:
11151134
# turn to next matched_atom_map
11161135
continue

rmgpy/rmg/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
from rmgpy.rmg.decay import decay_species
6060
from rmgpy.rmg.reactors import PhaseSystem, Phase, Interface, Reactor
6161
from rmgpy.molecule.fragment import Fragment
62-
62+
from rmgpy.molecule.molecule import Molecule
6363
################################################################################
6464

6565

0 commit comments

Comments
 (0)