Exemple #1
0
def format_coords(geo):
    """ format the coords section
    """

    # Get the number of atoms
    natoms = len(geo)

    # Get the geometry information
    symbols = geom.symbols(geo)
    coordinates = geom.coordinates(geo)
    masses = [int(ptab.to_mass(symbol)) for symbol in symbols]

    # Build a string with the formatted coordinates string
    if geom.is_atom(geo):
        geo_str = '{0:<4s}{1:<6d}'.format(symbols[0], masses[0])
    else:
        geo_str = ''
        for symbol, mass, coords in zip(symbols, masses, coordinates):
            coords = [coord * 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:<4s}{1:<6d}{2}\n'.format(symbol, mass, coords_str)
        # Remove final newline character from the string
        geo_str = geo_str.rstrip()

    return natoms, geo_str
Exemple #2
0
def sample_normal_modes(conformer, n_samples, temperature):
    """
    Take a conformer and return randomly sampled geometries by applying
    random displacements according to the normal modes of the molecule
    """
    atoms = conformer.atoms
    n_atoms = atoms.shape[0]
    original_xyz = conformer.xyz
    masses = [periodictable.to_mass(atom) for atom in atoms.tolist()]
    normal_modes = conformer.labels['normal modes']

    force_constants = conformer.labels['force constants']
    n_modes = len(normal_modes)
    kb = physical_constants.pc['boltzmann constant']

    new_coords = []
    for sample in range(n_samples):
        cis = torch.rand(n_modes)
        c_scale = torch.rand(1)
        cis = c_scale * cis / cis.sum()
        displacement_scalars = (
            ((torch.bernoulli(torch.fill(n_modes, 0.5)) - 0.5) * 2.0) *
            torch.sqrt(
                3.0 * cis * n_atoms * kb * temperature / force_constants))
        displacements = [
            mode * displacement_scalars[i]
            for i, mode in enumerate(normal_modes)
        ]
Exemple #3
0
def to_mass(atom):
    """ Obtain the atomic mass for a given atom (in amu).

        :param atom: atom representation (symbol, number, mass)
        :type atom: str/int
        :rtype: float
    """
    return periodictable.to_mass(atom)
Exemple #4
0
def atom_mass(har_min_cnf_locs, har_cnf_save_fs):
    """ write the atom string
    """
    har_geo = har_cnf_save_fs.leaf.file.geometry.read(har_min_cnf_locs)
    return ptab.to_mass(har_geo[0][0])
Exemple #5
0
def atom_to_mass(atom: Union[str, int]) -> float:
    """Give back the mass of a given element."""
    return periodictable.to_mass(atom)