Skip to content

Commit

Permalink
Add save to sdf functionality to io
Browse files Browse the repository at this point in the history
  • Loading branch information
jessbade committed Sep 11, 2023
1 parent d6c0c39 commit 5e70327
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions isicle/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,24 +153,22 @@ def load_nwchem(path, basename=None):
"""


dft = isicle.qm.NWChemWrapper()

parser = isicle.parse.NWChemParser()
parser.load(path)
result = parser.parse()

dft.__dict__.update(result)
dft.geom.add___dict__({k: v for k,
v in result.items() if k != 'geom'})
dft.geom.add___dict__({k: v for k, v in result.items() if k != "geom"})
dft.output = parser.load(path)

if basename is None:
try:
basename = Chem.MolToInchiKey(dft.geom.mol)
except:
basename = os.path.splitext((os.path.basename(path)))[0]

dft.basename = basename

return dft
Expand Down Expand Up @@ -307,7 +305,9 @@ def load_smiles(path, force=False, basename=None):
"""
extension = os.path.splitext(path)[-1].lower()
if "smi" in extension:
return _load_line_notation(path, func=Chem.MolFromSmiles, force=force, basename=basename)
return _load_line_notation(
path, func=Chem.MolFromSmiles, force=force, basename=basename
)
else:
return _load_line_notation(
path, func=Chem.MolFromSmiles, force=force, string=True, basename=basename
Expand Down Expand Up @@ -336,7 +336,9 @@ def load_inchi(path, force=False, basename=None):
path, func=Chem.MolFromInchi, force=force, string=True, basename=basename
)
else:
return _load_line_notation(path, func=Chem.MolFromInchi, force=force, basename=basename)
return _load_line_notation(
path, func=Chem.MolFromInchi, force=force, basename=basename
)


def load_pickle(path):
Expand Down Expand Up @@ -478,8 +480,6 @@ def load(path, force=False, basename=None):
return load_mol_obj(path, basename=basename)
except:
raise IOError("Not a valid RDKit mol object passed.")




def save_xyz(path, geom):
Expand Down Expand Up @@ -685,6 +685,29 @@ def save_pdb(path, geom):
Chem.MolToPDBFile(geom.mol, path)


def save_sdf(path, geom):
"""
Save molecule geometry(s) as SDF file.
Parameters
----------
path : str
Path to output file.
geom : :obj:`~isicle.geometry.Geometry` (or collection of)
Molecule representation.
"""
if isinstance(geom, isicle.geometry.Geometry):
w = Chem.SDWriter(path)
w.write(geom.mol)
w = None

elif isinstance(geom, isicle.geometry.Geometry):
w = Chem.SDWriter(path)
for m in geom.geom:
w.write(m.mol)
w = None


def save(path, data):
"""
Save molecule, format detected by path extension.
Expand Down

0 comments on commit 5e70327

Please sign in to comment.