Closed shihchengli closed 2 years ago
Looks good to me. Shih-Cheng, can you try to refactor save_opt_mol a bit?
def save_opt_mols(self,
save_dir: str,
opt_mol: 'RDKitMol',
keep_ids: dict = None,
energies: dict = None,
):
"""
Save the information of the optimized TS geometries into the directory.
Args:
save_dir (str): The path to the directory to save the results.
opt_mol (RDKitMol): The optimized TS molecule in RDKitMol with 3D conformer saved with the molecule.
keep_ids (dict): Dictionary of which opts succeeded and which failed
"""
# Save optimized ts mols
ts_path = os.path.join(save_dir, "ts_optimized_confs.sdf")
try:
ts_writer = Chem.rdmolfiles.SDWriter(ts_path)
for i in range(opt_mol.GetNumConformers()):
ts_writer.write(opt_mol, confId=i)
except Exception:
raise
finally:
ts_writer.close()
# save ids
with open(os.path.join(save_dir, "opt_check_ids.pkl"), "wb") as f:
pickle.dump(keep_ids, f)
Thanks @shihchengli, looks good to me. @PattanaikL The function save_opt_mols
needs to be refactorized later, though.
@staticmethod
as self
doesn't play a role in the functionopt_mol.ToRWMol()
needs to be done when calling the function save_opt_mol
instead of calling inside the function save_opt_mol
. In that case, keep_ids
, and energies
can be two optional arguments. If not provided, then try to get them from opt_mol.energies
and opt_mol.KeepIDs
Anyway, I will merge this PR and solve that later.
This addition allows the energy of each optimized TS to be saved in the .sdf file.