Skip to content

Commit

Permalink
Auto-PEP8: other tools in external
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoruiDong committed Sep 12, 2023
1 parent 966af55 commit ca4c585
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 87 deletions.
1 change: 0 additions & 1 deletion rdmc/external/networkx_mol.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,3 @@ def draw_networkx_mol(molgraph: nx.Graph) -> None:
labels=labels,
node_color=node_colors,
edgecolors='black',)

40 changes: 20 additions & 20 deletions rdmc/external/rmg.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ def load_rmg_database(families: list = [],
RMGDatabase: A instance of RMG database
"""
if all_families:
kinetics_families='all'
kinetics_families = 'all'
elif families:
kinetics_families=families
kinetics_families = families
else:
kinetics_families='default'
kinetics_families = 'default'
database_path = settings['database.directory']
database = RMGDatabase()
database.load(
Expand All @@ -50,7 +50,7 @@ def load_rmg_database(families: list = [],
return database


def load_rxn_family_database(families: Union[list,str] = 'all'):
def load_rxn_family_database(families: Union[list, str] = 'all'):
"""
A helper function to load RMG Kinetic database that only contains reaction family info.
Expand Down Expand Up @@ -176,9 +176,9 @@ def find_reaction_family(database: 'KineticsDatabase',
products = [mol.copy() for mol in products]

reaction_list = database.generate_reactions_from_families(
reactants=reactants,
products=products,
only_families=only_families)
reactants=reactants,
products=products,
only_families=only_families)
# Get reaction information
all_matches = []
for rxn in reaction_list:
Expand Down Expand Up @@ -211,7 +211,7 @@ def generate_reaction_complex(database: 'KineticsDatabase',
Then, it will form a reactant complexes based on the `reactants` list. Finally, it will apply the template
corresponding to the family to the reactants complex and yield a product complex with the correct atom map.
One can bypasses the searching step by providing ``only_families`` with a single-element list and assigning
the forward variable. All allowed families names can be found at https://rmg.mit.edu/database/kinetics/families/.
the forward variable. All allowed families names can be found at https://rmg.mit.edu/database/kinetics/families/.
Please note that this function currently only returns the first template it finds. This is non-idea if a nominal
reaction has multiple channels.
# TODO: provide an option if multiple channel if available.
Expand Down Expand Up @@ -245,16 +245,16 @@ def generate_reaction_complex(database: 'KineticsDatabase',
# Find the reaction in the RMG database
try:
family_label, forward = find_reaction_family(database,
reactants,
products,
only_families=only_families,
verbose=verbose,
resonance=resonance)
reactants,
products,
only_families=only_families,
verbose=verbose,
resonance=resonance)
# Cannot find any matches
except TypeError:
return None, None
else:
if family_label == None:
if family_label is None:
return None, None

# Make the reaction family preserver atom orders
Expand Down Expand Up @@ -295,10 +295,10 @@ def generate_reaction_complex(database: 'KineticsDatabase',
for r in reactants:
try:
resonanced_r = r.copy(deep=True).generate_resonance_structures(keep_isomorphic=False,
filter_structures=True,
save_order=True)
filter_structures=True,
save_order=True)
r_to_gen.append(resonanced_r)
except:
except BaseException:
r_to_gen.append([r])
rs_to_gen = list(set_product(*r_to_gen))
p_to_match = [p.copy(deep=True).generate_resonance_structures() for p in products]
Expand All @@ -308,7 +308,7 @@ def generate_reaction_complex(database: 'KineticsDatabase',
ps_to_match = [products]

for reactants in rs_to_gen:
# A = B or A = B + C
# A = B or A = B + C
if len(reactants) == 1:
# Find all possible mappings
mappings = family._match_reactant_to_template(reactants[0], template_reactants[0])
Expand Down Expand Up @@ -345,8 +345,8 @@ def generate_reaction_complex(database: 'KineticsDatabase',
else:
for struct in reactants:
reactant_structure = reactant_structure.merge(
struct.copy(deep=True)
)
struct.copy(deep=True)
)

# Make a copy for the reactant complex for output
reactant_complex = reactant_structure.copy(deep=True)
Expand Down
5 changes: 2 additions & 3 deletions rdmc/external/xtb_tools/opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ def get_homo_and_lumo_energies(data):
if data["number of unpaired electrons"] != 0:
print("Unpaired electrons are not supported for HOMO/LUMO data extraction.")
return np.nan, np.nan
num_occupied = (
np.array(data["fractional occupation"]) > 1e-6
).sum() # number of occupied orbitals; accounting for occassional very small values
# number of occupied orbitals; accounting for occassional very small values
num_occupied = (np.array(data["fractional occupation"]) > 1e-6).sum()
E_homo = data["orbital energies/eV"][num_occupied - 1] # zero-indexing
E_lumo = data["orbital energies/eV"][num_occupied]
return E_homo, E_lumo
Expand Down
2 changes: 1 addition & 1 deletion rdmc/external/xtb_tools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@ def get_bond_aidxs(mol):
begin_idx = mol.OBMol.GetBondById(i).GetBeginAtomIdx() - 1
end_idx = mol.OBMol.GetBondById(i).GetEndAtomIdx() - 1
atom_idxs.append((min(begin_idx, end_idx), max(begin_idx, end_idx)))
return atom_idxs
return atom_idxs
Loading

0 comments on commit ca4c585

Please sign in to comment.