Beispiel #1
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
Beispiel #2
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
Beispiel #3
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]))