Skip to content

Commit ee6971e

Browse files
committed
simplify auto cut algorithm
1 parent a314c4d commit ee6971e

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

rmgpy/rmg/model.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -303,18 +303,17 @@ def make_new_species(self, object, label="", reactive=True, check_existing=True,
303303

304304
# If we're here then we're ready to make the new species
305305
if check_cut:
306-
#set size_threshold to about half the molecule size
306+
# set size_threshold to about half the molecule size
307307
size_threshold = int((molecule.smiles.count("C")+molecule.smiles.count("c"))/2)
308-
#try to cut_molecule with size threshold set above, if error, try with default size_threshold
309-
try:
310-
mols = molecule.cut_molecule(cut_through=False,size_threshold=size_threshold)
311-
except:
312-
try:
313-
mols = molecule.cut_molecule(cut_through=False)
314-
except AttributeError:
315-
# it's Molecule object, change it to Fragment and then cut
316-
molecule = Fragment().from_adjacency_list(molecule.to_adjacency_list())
317-
mols = molecule.cut_molecule(cut_through=False)
308+
# if the molecule type is Molecule, change type to Fragment before cutting
309+
if type(molecule) == Molecule:
310+
molecule = Fragment().from_adjacency_list(molecule.to_adjacency_list())
311+
# try to cut_molecule with size threshold set above
312+
mols = molecule.cut_molecule(cut_through=False,size_threshold=size_threshold)
313+
# if cut above can't be made try with default size_threshold = 5
314+
if len(mols) == 1:
315+
mols = molecule.cut_molecule(cut_through=False)
316+
# if cut above can't be made, don't cut
318317
if len(mols) == 1:
319318
molecule = mols[0]
320319
else:

0 commit comments

Comments
 (0)