Skip to content

Commit 869f5ed

Browse files
doneranclhwpang
andauthored
Apply suggestions from code review - formatting, small things
Co-authored-by: Hao-Wei Pang <45482070+hwpang@users.noreply.github.com>
1 parent b89561d commit 869f5ed

4 files changed

Lines changed: 15 additions & 18 deletions

File tree

rmgpy/molecule/fragment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ def sliceitup_arom(self, molecule, size_threshold=5):
987987
# else if frag 1 and frag 2 have equal number
988988
# of Rs and Ls or one frag has more Rs and
989989
# more Ls than the other, choose randomly
990-
elif randint(0,1)==1:
990+
elif randint(0, 1) == 1:
991991
frag1_smi = frag1.replace("*", "L")
992992
frag2_smi = frag2.replace("*", "R")
993993
else:

rmgpy/molecule/fragment_utils.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -314,13 +314,12 @@ def merge_frag_list(to_be_merged):
314314
# print(newfraglist)
315315
return newfraglist
316316

317-
import re
318317
def check_if_radical_near_cutting_label(species_smiles):
319318
species_fragment = Fragment().from_smiles_like_string(species_smiles)
320319
for i, atom in enumerate(species_fragment.atoms):
321320
species_fragment.atoms[i].id = i
322321
for atom in species_fragment.atoms:
323-
if atom.radical_electrons ==1:
322+
if atom.radical_electrons == 1:
324323
bonded_atoms = list(atom.bonds.keys())
325324
bonded_atom_types = [type(x) for x in bonded_atoms]
326325
if CuttingLabel in bonded_atom_types:
@@ -358,7 +357,7 @@ def check_if_pibond_near_cutting_label(species_smiles):
358357
else:
359358
return False
360359

361-
def merge_fragment_a_to_cutting_label_on_b(smiles_a,smiles_b,cuttinglabel):
360+
def merge_fragment_a_to_cutting_label_on_b(smiles_a, smiles_b, cuttinglabel):
362361
a_frag = Fragment().from_smiles_like_string(smiles_a)
363362
b_frag = Fragment().from_smiles_like_string(smiles_b)
364363
for vertex in b_frag.vertices:
@@ -552,19 +551,19 @@ def generate_add_partial_reattachment_reactions(seed_dir, starting_fragments):
552551
seed_reactions_filename = os.path.join(seed_dir, "reactions.py")
553552
seed_dictionary_filename = os.path.join(seed_dir, "dictionary.txt")
554553

555-
with open(seed_dictionary_filename,'r') as f:
554+
with open(seed_dictionary_filename, 'r') as f:
556555
dictionary_lines = f.readlines()
557556

558557
fragment_to_name_dictionary = {}
559558

560559
dlines_iter = iter(dictionary_lines)
561-
name = next(dlines_iter,"end").strip().strip('\n')
562-
line = next(dlines_iter,"end")
560+
name = next(dlines_iter, "end").strip().strip('\n')
561+
line = next(dlines_iter, "end")
563562
while line != "end" and name !="end":
564-
species_adjlist =""
563+
species_adjlist = ""
565564
line = next(dlines_iter,"end")
566565
while line.strip().strip('\n') != "":
567-
species_adjlist +=line
566+
species_adjlist += line
568567
line = next(dlines_iter, "end")
569568

570569
f = Fragment().from_adjacency_list(species_adjlist)
@@ -576,7 +575,7 @@ def generate_add_partial_reattachment_reactions(seed_dir, starting_fragments):
576575
smiles = f.smiles
577576
try:
578577
for starting_fragment in starting_fragments:
579-
options = process_new_fragment(smiles, starting_fragment,species_cutting_threshold=12)
578+
options = process_new_fragment(smiles, starting_fragment, species_cutting_threshold=12)
580579
if type(options) == list:
581580
for option in options:
582581
option_frags = [Fragment().from_smiles_like_string(x) for x in option]
@@ -603,7 +602,7 @@ def generate_add_partial_reattachment_reactions(seed_dir, starting_fragments):
603602
\"\"\",
604603
)"""
605604

606-
with open(seed_reactions_filename,"r") as f:
605+
with open(seed_reactions_filename, "r") as f:
607606
lines = f.readlines()
608607
for line in lines[::-1]:
609608
if "index = " in line:
@@ -625,7 +624,7 @@ def generate_add_partial_reattachment_reactions(seed_dir, starting_fragments):
625624
entry = seed_reaction_template.format(largest_idx +j,rxn_str)
626625
seed_reaction_entries.append(entry+"\n")
627626

628-
if seed_reaction_entries != []:
627+
if seed_reaction_entries:
629628
with open(seed_reactions_filename,'a') as f:
630629
f.writelines(seed_reaction_entries)
631630
return f"Added {len(seed_reaction_entries)} partial reattachment reactions to {seed_reactions_filename}."

rmgpy/rmg/model.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,15 +306,14 @@ def make_new_species(self, object, label="", reactive=True, check_existing=True,
306306
# set size_threshold to about half the molecule size
307307
size_threshold = int((molecule.smiles.count("C")+molecule.smiles.count("c"))/2)
308308
# if the molecule type is Molecule, change type to Fragment before cutting
309-
if type(molecule) == Molecule:
309+
if isinstance(molecule, Molecule):
310310
molecule = Fragment().from_adjacency_list(molecule.to_adjacency_list())
311311
# try to cut_molecule with size threshold set above
312-
mols = molecule.cut_molecule(cut_through=False,size_threshold=size_threshold)
312+
mols = molecule.cut_molecule(cut_through=False, size_threshold=size_threshold)
313313
# if cut above can't be made try with default size_threshold = 5
314314
if len(mols) == 1:
315315
mols = molecule.cut_molecule(cut_through=False)
316-
# if cut above can't be made, don't cut
317-
if len(mols) == 1:
316+
# if cut above can't be made, don't cut
318317
molecule = mols[0]
319318
else:
320319
return [self.make_new_species(mol, check_decay=check_decay) for mol in mols]

rmgpy/yml.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@ def obj_to_dict(obj, spcs, names=None, label="solvent"):
141141
result_dict["type"] = "ElementaryReaction"
142142
result_dict["radicalchange"] = sum([get_radicals(x) for x in obj.products]) - \
143143
sum([get_radicals(x) for x in obj.reactants])
144-
if not obj.reversible:
145-
result_dict["reversible"] = obj.reversible
144+
result_dict["reversible"] = obj.reversible
146145
result_dict["comment"] = obj.kinetics.comment
147146
elif isinstance(obj, Arrhenius):
148147
obj.change_t0(1.0)

0 commit comments

Comments
 (0)