Skip to content

Commit

Permalink
Merge pull request #502 from avcopan/dev
Browse files Browse the repository at this point in the history
Dummy atom handling + nan values in potential
  • Loading branch information
avcopan authored Jun 13, 2024
2 parents bac0dc7 + 26d65ef commit 294af8a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
2 changes: 1 addition & 1 deletion automol/data/potent.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def dict_(
key: str = "energy",
index: bool = False,
zero_start_coord: bool = False,
drop_null: bool = False,
drop_null: bool = True,
) -> Dict[tuple, float]:
"""Convert a potential to a dictionary
Expand Down
40 changes: 30 additions & 10 deletions automol/geom/_conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import pyparsing as pp
from numpy.typing import ArrayLike
from pyparsing import pyparsing_common as ppc
from phydat import phycon

from automol import vmat
from automol.extern import molfile, py3dmol_, rdkit_
Expand All @@ -28,13 +29,13 @@
subgeom,
symbols,
translate,
without_dummy_atoms,
xyz_string,
)
from automol.graph import base as graph_base
from automol.inchi import base as inchi_base
from automol.util import ZmatConv, dict_, heuristic, vector, zmat_conv
from automol.zmat import base as zmat_base
from phydat import phycon


# # conversions
Expand Down Expand Up @@ -437,30 +438,42 @@ def _parse_sort_order_from_aux_info(aux_info):
return nums_lst


def molfile_with_atom_mapping(gra, geo=None):
def molfile_with_atom_mapping(
gra, geo=None, dummy: bool = False, bond_order: bool = True
):
"""Generate an MOLFile from a molecular graph.
If coordinates are passed in, they are used to determine stereo.
:param gra: molecular graph
:type gra: automol graph data structure
:param geo: molecular geometry
:type geo: automol geometry data structure
:param dummy: Include dummy atoms?
:param bond_order: Include bond orders?
:returns: the MOLFile string, followed by a mapping from MOLFile atoms
to atoms in the graph
:rtype: (str, dict)
"""
gra = graph_base.without_dummy_atoms(gra)
gra = graph_base.kekule(gra)
gra = graph_base.without_bonds_by_orders(gra, ords=[0], skip_dummies=False)
if not dummy:
gra = graph_base.without_dummy_atoms(gra)
geo = None if geo is None else without_dummy_atoms(geo)

if bond_order:
gra = graph_base.kekule(gra)

atm_keys = sorted(graph_base.atom_keys(gra))
bnd_keys = list(graph_base.bond_keys(gra))
atm_syms = dict_.values_by_key(graph_base.atom_symbols(gra), atm_keys)
atm_syms = dict_.values_by_key(
graph_base.atom_symbols(gra, dummy_symbol="He"), atm_keys
)
atm_bnd_vlcs = dict_.values_by_key(graph_base.atom_bond_counts(gra), atm_keys)
atm_rad_vlcs = dict_.values_by_key(
graph_base.atom_unpaired_electrons(gra), atm_keys
)
bnd_ords = dict_.values_by_key(graph_base.bond_orders(gra), bnd_keys)

atm_xyzs = None if geo is None else coordinates(geo)
atm_xyzs = None if geo is None else coordinates(geo, angstrom=True)

mlf, key_map_inv = molfile.from_data(
atm_keys,
Expand Down Expand Up @@ -568,9 +581,16 @@ def py3dmol_view(
if gra is not None and graph_base.is_ts_graph(gra):
gra = graph_base.ts.reactants_graph(gra, stereo=False, dummy=True)

xyz_str = xyz_string(geo, mode=mode)
return py3dmol_.view_molecule_from_xyz(
xyz_str, view=view, image_size=image_size, vib=(mode is not None)
if mode is not None:
xyz_str = xyz_string(geo, mode=mode)
return py3dmol_.view_molecule_from_xyz(
xyz_str, view=view, image_size=image_size, vib=True
)

gra = graph(geo, stereo=False) if gra is None else gra
mlf_str, _ = molfile_with_atom_mapping(gra, geo, dummy=True, bond_order=False)
return py3dmol_.view_molecule_from_molfile(
mlf_str, view=view, image_size=image_size
)


Expand Down Expand Up @@ -697,7 +717,7 @@ def closest_unbonded_atom_distances(
:rtype: Dict[int, float]
"""
gra = graph_without_stereo(geo) if gra is None else gra
idxs = graph_base.atom_keys(gra)
idxs = graph_base.atom_keys(gra, excl_symbs=["X"])
idxs -= graph_base.atom_neighbor_atom_keys(
gra, idx, include_self=True, second_degree=excl_second_degree
)
Expand Down

0 comments on commit 294af8a

Please sign in to comment.