Example #1
0
def add_element(fml, symb, num=1):
    """ add or subtract (if num < 0) this element from the molecular formula

        :param fml: stochiometric chemical formula
        :type fml: dict[str:int]
        :param symb: atomic symbol of element to be added
        :type symb: str
        :param num: number of the element to add to the formula
        :type num: int
        :rtype: dict[str:int]
    """

    assert ptab.to_number(symb)
    assert _is_standard(fml)

    symb = ptab.to_symbol(symb)
    fml = fml.copy()
    if symb in fml:
        fml[symb] += num
    else:
        fml[symb] = num

    assert fml[symb] > 0

    return fml
Example #2
0
def heavy_atom_count(gra, dummy=False):
    """ the number of heavy atoms
    """
    if not dummy:
        gra = without_dummy_atoms(gra)
    atm_symb_dct = atom_symbols(gra)
    nhvy_atms = sum(ptab.to_number(sym) != 1 for sym in atm_symb_dct.values())
    return nhvy_atms
Example #3
0
def without_dummy_atoms(gra):
    """ remove dummy atoms from the graph
    """
    atm_symb_dct = atom_symbols(gra)
    atm_keys = [
        key for key, sym in atm_symb_dct.items() if ptab.to_number(sym)
    ]
    return subgraph(gra, atm_keys, stereo=True)
Example #4
0
def heuristic_bond_distance(gra, key1, key2, angstrom=True, check=False):
    """ heuristic bond distance (in angstroms)
    """
    if check:
        assert key1 in atoms_neighbor_atom_keys(gra)[key2]

    symb_dct = atom_symbols(gra)
    symb1 = symb_dct[key1]
    symb2 = symb_dct[key2]

    if ptab.to_number(symb1) == 1 or ptab.to_number(symb2) == 1:
        dist = XH_DIST
    else:
        dist = XY_DIST

    dist *= 1 if angstrom else phycon.ANG2BOHR

    return dist
Example #5
0
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)
Example #6
0
def _encode_vertex_attributes(sym, imp_hyd_vlc, par):
    """ encode vertex attributes as an integer (or "color")

    scheme:
        atomic symbol               <=> hundreds place, as atomic number
        implicit hydrogen valence   <=> tens place
        parity                      <=> ones place (None->0, False->1, True->2)
    """
    id3 = ptab.to_number(sym)
    id2 = imp_hyd_vlc
    id1 = 0 if par is None else 1 + int(par)

    color = id3 * 100 + id2 * 10 + id1 * 1
    return color
Example #7
0
def dummy_atom_indices(geo):
    """ Obtain the indices of a atoms of a particular type in the geometry.

        :param geo: molecular geometry
        :type geo: automol molecular geometry data structure
        :rtype: tuple(int)
    """

    symbs = symbols(geo)
    dummy_idxs = [
        idx for idx, symb in enumerate(symbs) if not ptab.to_number(symb)
    ]

    return tuple(dummy_idxs)
Example #8
0
def electron_count(fml):
    """ Count the number of electrons for the atoms in a molecular formula.

        :param fml: stochiometric chemical formula
        :type fml: dict[str:int]
        :rtype: int
    """

    assert _is_standard(fml)

    elec_count = 0
    for key in fml:
        value = fml[key]
        elec_count += value * ptab.to_number(key)

    return elec_count
Example #9
0
def _format_geo_str(geo):
    """ Formats a geometry into a string used for the ProjRot input file.

        :param geo: geometries (Angstrom)
        :type geo: list
        :rtype: str
    """

    # Format the strings for the xyz coordinates
    geo_str = ''
    for i, (sym, xyzs) in enumerate(geo):
        anum = int(ptab.to_number(sym))
        xyzs = [xyz * phycon.BOHR2ANG for xyz in xyzs]
        xyzs_str = f'{xyzs[0]:>14.8f}{xyzs[1]:>14.8f}{xyzs[2]:>14.8f}'
        geo_str += f'{i+1:2d}{anum:4d}{0:4d}{xyzs_str}\n'

    return remove_trail_whitespace(geo_str)
Example #10
0
def _format_geo_str(geo):
    """ Formats a geometry into a string used for the ProjRot input file.

        :param geo: geometries (Angstrom)
        :type geo: list
        :rtype: str
    """

    # Format the strings for the xyz coordinates
    geo_str = ''
    for i, (sym, coords) in enumerate(geo):
        anum = int(ptab.to_number(sym))
        coords = [coord * phycon.BOHR2ANG for coord in coords]
        coords_str = '{0:>14.8f}{1:>14.8f}{2:>14.8f}'.format(
            coords[0], coords[1], coords[2])
        geo_str += '{0:2d}{1:4d}{2:4d}{3}\n'.format(i + 1, anum, 0, coords_str)

    return remove_trail_whitespace(geo_str)
Example #11
0
def _format_grad_str(geo, grad):
    """ Formats a gradient into a string used for the ProjRot input file.

        :param geom: geometries (Angstrom)
        :type geom: list
        :param grads: gradients (Eh/Bohr)
        :type grads: list
        :rtype: str
    """

    atom_list = []
    for i, (sym, _) in enumerate(geo):
        atom_list.append(int(ptab.to_number(sym)))

    # Format the strings for the xyz gradients
    full_grads_str = ''
    for i, grads in enumerate(grad):
        grads_str = f'{grads[0]:>14.8f}{grads[1]:>14.8f}{grads[2]:>14.8f}'
        full_grads_str += f'{i+1:2d}{atom_list[i]:4d}{grads_str}\n'

    return remove_trail_whitespace(full_grads_str)
Example #12
0
def dummy_coordinate_names(vma):
    """ Obtain names of all coordinates associated with dummy atoms
        defined in the V-Matrix.

        :param vma: V-Matrix
        :type vma: automol V-Matrix data structure
        :rtype: tuple(str)
    """

    symbs = symbols(vma)
    name_mat = numpy.array(name_matrix(vma))
    dummy_keys = [idx for idx, sym in enumerate(symbs)
                  if not ptab.to_number(sym)]
    dummy_names = []
    for dummy_key in dummy_keys:
        for col_idx in range(3):
            dummy_name = next(filter(lambda x: x is not None,
                                     name_mat[dummy_key:, col_idx]))
            dummy_names.append(dummy_name)

    dummy_names = tuple(dummy_names)

    return dummy_names