Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When fetching a mol from PubChem, use 2d pos if 3d pos not found #115

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions pyscf_ipu/nanoDFT/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,16 @@ def get_mol_str_pubchem(entry: str):
'entry' is interpreted as Compound ID if it is a string of digits or as
name of a compound otherwise"""

if entry.isdigit(): # If all digits, we assume it is a CID
if entry.isdigit(): # If all digits, we assume it is a CID
print(f"Searching in PubChem for CID '{entry}'")
compound = pubchempy.get_compounds(entry, "cid", record_type='3d')
else:
print(f"Searching in PubChem for compound with name '{entry}'") # if not, we assume it is a name
if len(compound) == 0:
compound = pubchempy.get_compounds(entry, 'cid', record_type='2d')
else: # if not, we assume it is a name
print(f"Searching in PubChem for compound with name '{entry}'")
compound = pubchempy.get_compounds(entry, 'name', record_type='3d')
if len(compound) == 0:
compound = pubchempy.get_compounds(entry, 'name', record_type='2d')
mol_str = []
if len(compound) > 1:
print("INFO: PubChem returned more than one compound; using the first...", file=sys.stderr)
Expand All @@ -71,7 +75,8 @@ def get_mol_str_pubchem(entry: str):
return None
print(f"Found compound: {compound[0].synonyms[0]}")
for a in compound[0].atoms:
mol_str.append((a.element,np.array([a.x, a.y, a.z])))
z = a.z or 0.0
mol_str.append((a.element,np.array([a.x, a.y, z])))
return mol_str


Expand Down