Skip to content

Commit cce37c6

Browse files
committed
Deploy website
0 parents  commit cce37c6

File tree

543 files changed

+98735
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

543 files changed

+98735
-0
lines changed

.nojekyll

Whitespace-only changes.

build/lib/mispr/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "0.0.4"

build/lib/mispr/common/__init__.py

Whitespace-only changes.

build/lib/mispr/common/pubchem.py

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
"""Implement a core class PubChemRunner for retrieving molecules from the PubChem
2+
database using a molecule name as a query criteria."""
3+
4+
import os
5+
6+
import pubchempy as pcp
7+
8+
from pymatgen.core.structure import Molecule
9+
10+
__author__ = "Rasha Atwi"
11+
__maintainer__ = "Rasha Atwi"
12+
__email__ = "rasha.atwi@stonybrook.edu"
13+
__status__ = "Development"
14+
__date__ = "Aug 2022"
15+
__version__ = "0.0.4"
16+
17+
18+
class PubChemRunner:
19+
"""
20+
Wrapper for retrieving molecules from PubChem database.
21+
"""
22+
23+
def __init__(self, abbreviation, working_dir=None):
24+
"""
25+
Args:
26+
abbreviation (str): Abbreviation to be used when saving molecule file.
27+
working_dir (str, optional): Working directory for saving the molecule file
28+
in; will use the current working directory if not specified.
29+
"""
30+
self.abbreviation = abbreviation
31+
self.working_dir = working_dir or os.getcwd()
32+
self.cid = None
33+
34+
def get_mol(self, name, save_to_file=True, fmt="pdb", cleanup=True):
35+
"""
36+
Wrapper function that searches for a molecule in the PubChem database, downloads
37+
it in the form of an SDF file, and converts the file to a pymatgen ``Molecule``
38+
object.
39+
40+
Args:
41+
name (str): Name of the molecule to use for searching PubChem.
42+
save_to_file (bool, optional): Whether to save the ``Molecule`` object to a
43+
file. Defaults to ``True``.
44+
fmt (str, optional): Molecule file format if ``save_to_file`` is ``True``;
45+
defaults to "pdb".
46+
cleanup (bool, optional): Whether to remove the intermediate sdf file.
47+
48+
Returns:
49+
Molecule: pymatgen ``Molecule`` object.
50+
"""
51+
self.download_sdf(name)
52+
molecule = self.convert_sdf_to_mol(save_to_file, fmt)
53+
if cleanup:
54+
self.cleanup()
55+
return molecule
56+
57+
def download_sdf(self, name):
58+
"""
59+
Download an SDF file from PubChem using a common name for the molecule as an
60+
identifier.
61+
62+
Args:
63+
name (str): Name of the molecule to use for searching PubChem.
64+
"""
65+
cids = pcp.get_cids(name, record_type="3d")
66+
if cids:
67+
self.cid = cids[0]
68+
pcp.download(
69+
outformat="SDF",
70+
path=f"{self.working_dir}/{self.abbreviation}_{self.cid}.sdf",
71+
identifier=self.cid,
72+
record_type="3d",
73+
overwrite=True,
74+
)
75+
else:
76+
raise ValueError("No matching molecule found in the PubChem database")
77+
78+
def convert_sdf_to_mol(self, save_to_file, fmt):
79+
"""
80+
Convert an SDF file to a pymatgen ``Molecule`` object.
81+
82+
Args:
83+
save_to_file (bool): Whether to save the ``Molecule`` object to a file.
84+
fmt (str): Molecule file format if ``save_to_file`` is ``True``.
85+
86+
Returns:
87+
Molecule: pymatgen ``Molecule`` object.
88+
"""
89+
mol = Molecule.from_file(
90+
f"{self.working_dir}/{self.abbreviation}_{self.cid}.sdf"
91+
)
92+
if save_to_file:
93+
mol.to(fmt, f"{self.working_dir}/{self.abbreviation}_{self.cid}.{fmt}")
94+
return mol
95+
96+
def cleanup(self):
97+
"""
98+
Delete the sdf file downloaded from PubChem.
99+
"""
100+
os.remove(f"{self.working_dir}/{self.abbreviation}_{self.cid}.sdf")

build/lib/mispr/gaussian/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)