def without_dummy_atoms(geo): """ Return a copy of the molecular geometry without dummy atoms. """ symbs = symbols(geo) non_dummy_idxs = [ idx for idx, symb in enumerate(symbs) if ptab.to_number(symb) ] return from_subset(geo, non_dummy_idxs)
def formula(geo): """ Generate a stoichiometric formula dictionary from a molecular geometry. :param geo: molecular geometry :type geo: automol geometry data structure :type: dict[str: int] """ symbs = symbols(geo) fml = _util.formula(symbs) return fml
def connectivity_graph(geo, rqq_bond_max=3.45, rqh_bond_max=2.6, rhh_bond_max=1.9): """ Generate a molecular graph from the molecular geometry that has information about bond connectivity. :param rqq_bond_max: maximum distance between heavy atoms :type rqq_bond_max: float :param rqh_bond_max: maximum distance between heavy atoms and hydrogens :type rqh_bond_max: float :param rhh_bond_max: maximum distance between hydrogens :type rhh_bond_max: float :rtype: automol molecular graph structure """ symbs = symbols(geo) xyzs = coordinates(geo) def _distance(idx_pair): xyz1, xyz2 = map(xyzs.__getitem__, idx_pair) dist = numpy.linalg.norm(numpy.subtract(xyz1, xyz2)) return dist def _are_bonded(idx_pair): sym1, sym2 = map(symbs.__getitem__, idx_pair) dist = _distance(idx_pair) return (False if 'X' in (sym1, sym2) else (dist < rqh_bond_max) if 'H' in (sym1, sym2) else (dist < rhh_bond_max) if (sym1 == 'H' and sym2 == 'H') else (dist < rqq_bond_max)) idxs = range(len(xyzs)) atm_symb_dct = dict(enumerate(symbs)) bnd_keys = tuple( map(frozenset, filter(_are_bonded, itertools.combinations(idxs, r=2)))) bnd_ord_dct = {bnd_key: 1 for bnd_key in bnd_keys} gra = create.graph.from_data(atom_symbols=atm_symb_dct, bond_keys=bnd_keys, bond_orders=bnd_ord_dct) return gra
def from_subset(geo, idxs): """ Generate a new molecular geometry from a subset of the atoms in an input geometry. (Rename this and put it under operations?) :param geo: molecular geometry :type geo: automol molecular geometry data structure :param idxs: indices representing the subset of atoms :type idxs: tuple(int) :rtype: automol moleculer geometry data structure """ symbs = symbols(geo) xyzs = coordinates(geo) symbs = list(map(symbs.__getitem__, idxs)) xyzs = list(map(xyzs.__getitem__, idxs)) return automol.create.geom.from_data(symbs, xyzs)
def insert(geo, symb, xyz, idx=None, angstrom=False): """ Insert an atom into a molecular geometry. :param geo: molecular geometry :type geo: automol molecular geometry data structure :param symb: symbol of atom to add :type symb: str :param xyz: xyz coordinates of atom to add :type xyz: tuple(float) :param idx: index of geometry to place atom :type idx: int :rtype: automol geometry date structure """ symbs = list(symbols(geo)) xyzs = list(coordinates(geo, angstrom=angstrom)) idx = idx if idx is not None else len(symbs) symbs.insert(idx, symb) xyzs.insert(idx, xyz) return automol.create.geom.from_data(symbs, xyzs, angstrom=angstrom)