Ejemplo n.º 1
0
def hc1_complete_cell():
    """HC1 completed cell"""
    cell = Mol(rf.read_pos(_in_data("hc1_complete_cell.xyz")))
    vectors = np.array([[12.1199998856, 0.0, 0.0], [0.0, 10.2849998474, 0.0],
                        [-5.4720203118, 0.0, 11.2441994632]])
    cell.vectors = vectors
    return cell
Ejemplo n.º 2
0
    def run(self, atoms):
        """
        Write a DFTB .gen file and return a subprocess.Popen

        Parameters
        ----------
        atoms : list of Atom objects
            Atoms to be calculated with DFTB+
        Returns
        -------
        proc : subprocess.Popen object
            the object should have a .wait() method

        """
        dftb_path = os.path.join(self.here, self.calc_name)
        os.chdir(dftb_path)

        mol = Mol(atoms)

        region_2_file = "r2.xyz"
        if os.path.exists(region_2_file):
            mol_r2 = rf.mol_from_file(region_2_file)
            mol += mol_r2

        mol.write_xyz("geom.xyz")
        subprocess.call("xyz2gen geom.xyz", shell=True)
        # Run DFTB+
        proc = subprocess.Popen("dftb+ > dftb_out", shell=True)

        os.chdir(self.here)

        return proc
Ejemplo n.º 3
0
def read_points(in_name):
    """
    Read point charges from an in-house Ewald.c output.

    The modified version of Ewald.c is needed. The extension is .pts-cry

    Parameters
    ----------
    in_name : str
        Name of the file to read
    Returns
    -------
    points : Mol object
        Point charges in the file. They have element "point"

    """
    with open(in_name) as pts_file:
        pts_content = pts_file.readlines()

        # store point charges here
    points = Mol([])

    for line in pts_content:
        xIn, yIn, zIn, qIn = map(float, line.split())
        point = Atom("point", xIn, yIn, zIn, qIn)
        points.append(point)

    return points
Ejemplo n.º 4
0
def test_fit_benz_clust_shell(benz_clust_char):
    sample_point = Atom("", 0, 0, 0)
    sample_point2 = Atom("", 0.1, 0, 0)
    sample_point.es = 0
    sample_point2.es = 0
    fixed_atoms = benz_clust_char.select(0)
    var_atoms = Mol([i for i in benz_clust_char if i not in fixed_atoms])
    fi.fit_points(var_atoms, fixed_atoms, Mol([sample_point, sample_point2]))
    return
Ejemplo n.º 5
0
def read_cube(in_file):
    """
    Read a cube file and return a Mol and a CubeGrid object

    Parameters
    ----------
    in_file : str
        Input file name
    Returns
    -------
    out_mol : Mol object
        The atoms in the cube file
    out_cub : CubeGrid object
        The grid in the cube file where all distances are in Angstrom

    """
    vectors = np.zeros((3, 3))
    xyz_nums = [0, 0, 0]
    values = []

    out_mol = Mol([])
    ind = 0
    natoms = 0
    with open(in_file) as lines:
        for line in lines:
            if ind == 2:
                natoms = int(line.split()[0])
                origin = np.array([float(i)
                                   for i in line.split()[1:]]) / pt.bohrconv
            if ind == 3:
                xyz_nums[0] = int(line.split()[0])
                vectors[0] = np.array([float(i) for i in line.split()[1:]
                                       ]) / pt.bohrconv
            if ind == 4:
                xyz_nums[1] = int(line.split()[0])
                vectors[1] = np.array([float(i) for i in line.split()[1:]
                                       ]) / pt.bohrconv
            if ind == 5:
                xyz_nums[2] = int(line.split()[0])
                vectors[2] = np.array([float(i) for i in line.split()[1:]
                                       ]) / pt.bohrconv
                out_cub = CubeGrid(vectors, xyz_nums[0], xyz_nums[1],
                                   xyz_nums[2], origin)
                out_cub.set_grid_coord()
            if 6 <= ind < (6 + natoms):
                line_s = line.split()
                new_atom = Atom()
                new_atom.elem = per.num_to_elem(int(line_s[0]))
                new_atom.set_pos([float(i) / pt.bohrconv for i in line_s[2:]])
                out_mol.append(new_atom)
            if ind >= (6 + natoms):
                values.extend([float(i) for i in line.split()])
            ind += 1
    values_arr = np.array(values)
    out_cub.grid[:, 3] = values_arr
    return out_cub, out_mol
Ejemplo n.º 6
0
def test():
    from fromage.utils.atom import Atom
    from fromage.utils.mol import Mol
    mol_a = Mol([Atom("C", 1)])
    mol_b = Mol([Atom("C", 2)])
    mol_c = Mol([Atom("C", 3)])
    mol_d = Mol([Atom("C", 4)])

    lis = [mol_a, mol_b, mol_c, mol_d]
    print(all_dimers(lis))
Ejemplo n.º 7
0
def test_same_atoms_as():
    mol_a_lis = [Atom("C", 1., 0., 0.), Atom("H", 1., 1., 1.)]
    mol_b_lis = [Atom("H", 1., 1., 1.), Atom("C", 1., 0., 0.)]
    mol_c_lis = [Atom("C", 1., 0., 0.), Atom("C", 1., 1., 1.)]
    mol_a = Mol(mol_a_lis)
    mol_b = Mol(mol_b_lis)
    mol_c = Mol(mol_c_lis)

    assert mol_a.same_atoms_as(mol_b) == True
    assert mol_a.same_atoms_as(mol_c) == False
Ejemplo n.º 8
0
def test_fit_to_pot(benz_pot_cub, benz_clust_char):
    print(benz_pot_cub.grid)
    sample_point = Atom("", 0, 0, 0)
    sample_point.es = 0.17671
    print(benz_clust_char.es_pot([0, 0, 0]))
    fixed_atoms = benz_clust_char.select(0)
    var_atoms = Mol([i for i in benz_clust_char if i not in fixed_atoms])
    fi.fit_points(var_atoms, fixed_atoms, Mol([sample_point]))
    out_clust = var_atoms + fixed_atoms
    print(out_clust.es_pot([0, 0, 0]))
    return
Ejemplo n.º 9
0
def test_fit_benz_clust(benz_clust_char):
    sample_point = Atom("", 0, 0, 0)
    sample_point2 = Atom("", 0.1, 0, 0)
    sample_point.es = 0
    sample_point2.es = 0
    fi.fit_points(benz_clust_char, None, Mol([sample_point, sample_point2]))
    return
Ejemplo n.º 10
0
def fit_points(var_points, samples, fix_points=None):
    """
    Return a new set of point charges that matches the potential at points

    Parameters
    ----------
    var_points : Mol object
        Point charges to be fitted
    samples : list of Mol objects or just one Mol object
        Sampling points each with an associated electrostatic potential
    fix_points : Mol object
        Point charges to remain in place
    Returns
    -------
    out_points : Mol object
        The points at their same position but with optimised charge value

    """
    if fix_points is None:
        fix_points = Mol([])
    coeffs = coeff_mat(var_points, samples)
    deps = dep_var(var_points, fix_points, samples)

    res = np.linalg.lstsq(coeffs, deps, rcond=None)

    print("RMSD: " + str(np.sqrt(np.sum(res[3]) / len(samples))))
    print(res[1:])
    fitting = res[0]
    print(fitting[0:6])
    var_points.change_charges(var_points.charges() + fitting)

    return var_points
Ejemplo n.º 11
0
def mol_from_gauss(in_name, pop="ESP"):
    """
    Read Mol from a Gaussian log file

    Include the requested charges.

    Parameters
    ----------
        in_name : str
            Name of the file to read
        pop : str, optional
            Type of charges requested
    Returns
    -------
        out_mol : Mol object
            The atoms in the Gaussian log file, along with their charge

    """
    atoms = read_g_pos(in_name)
    charges = read_g_char(in_name, pop=pop)[0]

    for i, char in enumerate(charges):
        atoms[i].q = char
    out_mol = Mol(atoms)

    return out_mol
Ejemplo n.º 12
0
def mol_from_file(in_name, bonding='', vectors=np.zeros((3, 3))):
    """
    Return a Mol object from a file

    Parameters
    ----------
    in_name : str
        Name of the file to read
    bonding : str
        A string determining the type of bonding in the molecule. Something like
        'dis0.2' or '-13cov'
    vectors : 3 x 3 np array
        The unit cell vectors if pertinent
    Returns
    -------
    atom_step : Mol object
        The atomic positions in the file

    """
    mol = Mol(read_pos(in_name))
    mol.vectors = vectors
    mol.set_bonding_str(bonding)

    return mol
Ejemplo n.º 13
0
def test_sample(benz_pot_cub, benz_cell):
    pts = fi.shell_region(benz_pot_cub.grid, benz_cell, 0.2, 0.7)
    out_mol = Mol([])
    for point in pts:
        out_mol.append(Atom("point", point[0], point[1], point[2]))
Ejemplo n.º 14
0
def hc1_quad():
    """HC1 quadrimer"""
    out_mo = Mol(rf.read_pos(_in_data("hc1_quad.xyz")))
    return out_mo
Ejemplo n.º 15
0
def h2o_dimer_mol(at_list):
    """Water dimer Mol object"""
    out_mo = Mol(at_list)
    return out_mo
Ejemplo n.º 16
0
def c_o():
    """CO Mol object"""
    c_at = Atom("C", 0.0, 0.0, 0.0)
    o_at = Atom("O", 1.0, 0.0, 0.0)
    out_mol = Mol([c_at, o_at])
    return out_mol
Ejemplo n.º 17
0
def h2o_dimer(at_list):
    """Return a water dimer Mol object"""
    out_mo = Mol(at_list)
    return out_mo
Ejemplo n.º 18
0
def test_add(h2o_dimer, newat):
    """Addition is implemented"""
    new_mol = h2o_dimer + Mol(newat)
    assert len(new_mol) == 7
Ejemplo n.º 19
0
def c_o():
    c_at = Atom("C", 0.0, 0.0, 0.0)
    o_at = Atom("O", 1.0, 0.0, 0.0)
    out_mol = Mol([c_at, o_at])
    return out_mol
Ejemplo n.º 20
0
def empty_mol():
    return Mol([])
Ejemplo n.º 21
0
def hc1_quad():
    """Return a HC1 quadrimer"""
    out_mo = Mol(rf.read_pos("hc1_quad.xyz"))
    return out_mo
Ejemplo n.º 22
0
def empty_mol():
    """Empty Mol object"""
    return Mol([])
Ejemplo n.º 23
0
def test_init():
    """The Mol object is initialised correctly"""
    mo = Mol(at_list())
    assert isinstance(mo, Mol)