Skip to content

Usability fixes for mol_str, min interatomic dist #130

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion pyscf_ipu/nanoDFT/nanoDFT.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,10 @@ def nanoDFT_options(
if mol_str is None:
exit(1)

print(f"Minimum interatomic distance: {utils.min_interatomic_distance(mol_str)}") # TODO: dies for --mol_str methane
m_i_d = utils.min_interatomic_distance(mol_str)
print(f"Minimum interatomic distance: {m_i_d}") # TODO: dies for --mol_str methane
if m_i_d < 0.7 or m_i_d > 1.8:
print("WARNING: the coordinates may be expressed in units other than angstrom")

args = locals()
mol_str = args["mol_str"]
Expand Down
13 changes: 8 additions & 5 deletions pyscf_ipu/nanoDFT/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
import h5py
import pubchempy
import pyscf
import numpy as np
from itertools import combinations
from operator import itemgetter
Expand Down Expand Up @@ -63,15 +64,15 @@ def get_mol_str_pubchem(entry: str):
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}'")
print(f"Searching in PubChem by name")
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)
elif len(compound) == 0:
print(f"No compound found with the name '{entry}' in PubChem")
print(f"No compound found in PubChem by CID or by name")
return None
print(f"Found compound: {compound[0].synonyms[0]}")
for a in compound[0].atoms:
Expand Down Expand Up @@ -138,9 +139,11 @@ def process_mol_str(mol_str: str):
elif mol_str in spice_amino_acids:
mol_str = get_mol_str_spice_aa(mol_str)
else:
mol_str = get_mol_str_pubchem(mol_str)

return mol_str
mol_str_pubchem = get_mol_str_pubchem(mol_str)
if mol_str_pubchem is not None:
return mol_str_pubchem

return pyscf.gto.mole.Mole().format_atom(mol_str)


def min_interatomic_distance(mol_str):
Expand Down