def main(file_name):
    xyz_file = XYZFile(file_name)
    frames = xyz_file.geometries
    #    titles = xyz_file.titles

    # Unit cell, decide how to make this general
    matrix = np.array([[
        1.4731497044857509E+01, 3.2189795740722255E-02, 4.5577626559295564E-02
    ], [
        4.2775481701113616E-02, 2.1087874593411915E+01, -2.8531114198383896E-02
    ], [
        6.4054385616337750E-02, 1.3315840416191497E-02, 1.4683043045316882E+01
    ]])
    matrix *= angstrom
    cell = UnitCell(matrix)
    frac = UnitCell.to_fractional(cell, frames)

    xmin = np.min(frac[:, :, 0])
    ymin = np.min(frac[:, :, 1])
    zmin = np.min(frac[:, :, 2])
    frac[:, :, 0] -= -0.5  # xmin
    frac[:, :, 1] -= -0.5  # ymin
    frac[:, :, 2] -= -0.5  # zmin
    decimals = np.modf(frac)[0]
    #    decimals[:,:,0] += xmin
    #    decimals[:,:,1] += ymin
    #    decimals[:,:,2] += zmin
    frac_wrapped = np.where(decimals < 0, 1 + decimals, decimals)
    #    frac_wrapped[:,:,0] += xmin
    #    frac_wrapped[:,:,1] += ymin
    #    frac_wrapped[:,:,2] += zmin
    cart_wrapped = UnitCell.to_cartesian(cell, frac_wrapped)

    xyz_file.geometries = cart_wrapped
    xyz_file.write_to_file(file_name.rsplit(".", 1)[0] + "_wrapped.xyz")
Example #2
0
 def test_many_separate(self):
     psf = PSFFile()
     molecule = XYZFile("input/ethene.xyz").get_molecule()
     psf.add_molecule(molecule)
     psf.add_molecule(molecule)
     molecule = XYZFile("input/tea.xyz").get_molecule()
     psf.add_molecule(molecule)
     psf.write_to_file("output/many_separate.psf")
Example #3
0
 def test_tetra(self):
     molecule = XYZFile("input/tetra.xyz").get_molecule()
     psf = PSFFile()
     psf.add_molecule(molecule)
     self.assert_(psf.bonds.shape[0] == 4)
     self.assert_(psf.bends.shape[0] == 6)
     psf.write_to_file("output/tetra.psf")
Example #4
0
 def test_distance_matrix(self):
     molecule = XYZFile("input/tpa.xyz").get_molecule()
     dm = 0
     for i in 0,1,2:
         dm += numpy.subtract.outer(molecule.coordinates[:,i],molecule.coordinates[:,i])**2
     dm = numpy.sqrt(dm)
     self.assert_((abs(molecule.distance_matrix - dm) < 1e-5).all(), "Wrong distance matrix")
Example #5
0
 def test_blind(self):
     m = XYZFile("input/precursor.xyz").get_molecule()
     def yield_positioned_objects():
         for row, coordinate in enumerate(m.coordinates):
             yield PositionedObject(row, coordinate)
     sbo = SparseBinnedObjects(yield_positioned_objects(), 7.1)
     environments = calculate_environments(sbo, 7)
Example #6
0
        def test_one(xyz_fn, checks, reorder=False):
            mol = XYZFile(xyz_fn).get_molecule()
            graph = MolecularGraph.from_geometry(mol)
            zmat_gen = ZMatrixGenerator(graph)
            if reorder is False:
                self.assertArraysEqual(zmat_gen.new_index, numpy.arange(mol.size))
                self.assertArraysEqual(zmat_gen.old_index, numpy.arange(mol.size))

            zmat0 = zmat_gen.cart_to_zmat(mol.coordinates)
            for field, index, value in checks:
                self.assertAlmostEqual(zmat0[field][index], value, 2, "%s:%i %f!=%f" % (field,index,zmat0[field][index],value))

            numbers0, coordinates0 = zmat_to_cart(zmat0)
            mol0 = Molecule(numbers0, coordinates0)
            mol0.write_to_file("output/zmat_%s" % os.path.basename(xyz_fn))
            graph0 = MolecularGraph.from_geometry(mol0)
            zmat_gen0 = ZMatrixGenerator(graph0)
            self.assertArraysEqual(zmat_gen0.new_index, numpy.arange(mol.size))
            self.assertArraysEqual(zmat_gen0.old_index, numpy.arange(mol.size))

            zmat1 = zmat_gen0.cart_to_zmat(mol0.coordinates)
            for field, index, value in checks:
                self.assertAlmostEqual(zmat1[field][index], value, 2, "%s:%i %f!=%f" % (field,index,zmat1[field][index],value))

            numbers1, coordinates1 = zmat_to_cart(zmat1)

            self.assertArraysEqual(numbers0, numbers1)
            self.assertArraysAlmostEqual(coordinates0, coordinates1, 1e-5)
Example #7
0
 def test_volume_dinitrogen(self):
     mol = XYZFile("input/dinitrogen.xyz").get_molecule()
     vdw_volume, sas_volume, ses_volume, error = estimate_volumes(mol)
     self.assert_(ses_volume > vdw_volume)
     self.assert_(sas_volume > ses_volume)
     r = periodic["N"].vdw_radius
     ses_upper_limit = 4.0 / 3.0 * numpy.pi * r**3 + numpy.pi * r**2 * numpy.linalg.norm(
         mol.coordinates[0] - mol.coordinates[1])
     self.assert_(vdw_volume < ses_upper_limit)
     self.assert_(ses_volume < ses_upper_limit)
Example #8
0
def main(file1_name, file2_name, start_step, end_step, trim, unitcell_name):
    """
    Takes a xyz trajectory and can combine it with the ptcv trajectory, trim it
    and add unit cell parameters in the title lines so that PLUMED can process it
    if the unit cell is variable

    """
    if os.path.isfile(file1_name):
        xyz_file1 = XYZFile(file1_name)
        xyz_file3 = xyz_file1
        geo1 = xyz_file1.geometries[start_step:end_step]

        if file2_name is not None:
            if os.path.isfile(file2_name):
                xyz_file2 = XYZFile(file2_name)
                geo2 = xyz_file2.geometries[start_step:end_step]

                xyz_file2.symbols = ('He', )
                min_size = min(geo1.shape[0], geo2.shape[0])

                xyz_file3.geometries = np.concatenate(
                    (geo1[:min_size:trim], geo2[:min_size:trim]), axis=1)
                xyz_file3.symbols = np.concatenate(
                    (xyz_file1.symbols, xyz_file2.symbols), axis=0)
                xyz_file3.write_to_file('coord-ptcv.xyz')

                if unitcell_name is not None:
                    unitcellmerge(xyz_file3, start_step, end_step, trim,
                                  unitcell_name)
            else:
                print('%s does not exist' % (file2_name))
        else:
            xyz_file3.geometries = geo1[::trim]
            if unitcell_name is not None:
                xyz_file3 = unitcellmerge(xyz_file3, start_step, end_step,
                                          trim, unitcell_name)
            xyz_file3.write_to_file('coord-processed.xyz')
    else:
        print('%s does not exist' % (file1_name))
Example #9
0
def main(file_name, parameters, start_step, end_step, temp):
    """
    Loads molecular geometries, generates file with time evolution
    of given angles and bonds. Prints force parameters for a
    harmonic oscillator that reproduces the behavior of
    each bond/angle to use as input for biased simulations
    """

    # Timestep in fs
    timestep = 0.5

    # Create output directory
    out_dir = "output_txt/"
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    # Create trajectory object and store the geometries in numpy array
    xyz_file = XYZFile(file_name)
    geometries = xyz_file.geometries[start_step:end_step]

    # Read atom list from input file (input is 1-based indexing)
    with open(parameters, 'r') as f:
        atoms_input = json.load(f)
    atoms = [np.array(a) - 1 for a in atoms_input]

    # Calculate bonds and angles
    time = (np.arange(geometries.shape[0]) + 1) * timestep
    bonds_angles = [get_bonds_angles(geometries, i) for i in atoms]
    labels = [convert_label(i) for i in atoms_input]

    # Compute histograms and saves results
    for i, qty in enumerate(bonds_angles):
        all_distr, coefficients = generate_histogram(qty, temp)

        np.savetxt("{}{}-hist.dat".format(out_dir, labels[i]), all_distr)
        np.savetxt("{}{}-time.dat".format(out_dir,
                                          labels[i]), np.stack((time, qty)).transpose())
        np.savetxt("{}{}-coeff.dat".format(out_dir,
                                           labels[i]),
                   coefficients,
                   fmt='%1.3f',
                   header='x0, sigma, k, R2')
        plot_all(all_distr, qty, coefficients, atoms_input[i], time)

    # Store in a pandas dataframe for further analysis (to do)
    all_data = pd.DataFrame(
        data=np.stack(bonds_angles).transpose(),
        index=time,
        columns=labels)
    all_data.to_csv("{}all_data.dat".format(out_dir), sep='\t')
Example #10
0
 def test_dihedral_ethene(self):
     mol = XYZFile("input/ethene.xyz").get_molecule()
     c = mol.coordinates.copy()
     self.assertAlmostEqual(ic.dihed_cos(c[2], c[0], c[3], c[5])[0], 1.0)
     self.assertAlmostEqual(ic.dihed_angle(c[2], c[0], c[3], c[5])[0], 0.0)
     for i in xrange(1000):
         angle = numpy.random.uniform(-numpy.pi, numpy.pi)
         radius = numpy.random.uniform(0, 5*angstrom)
         offset = numpy.random.uniform(0, 5*angstrom)
         c[5] = [
             offset,
             -radius*numpy.cos(angle),
             radius*numpy.sin(angle),
         ]
         self.assertAlmostEqual(ic.dihed_cos(c[2], c[0], c[3], c[5])[0], numpy.cos(angle))
         self.assertAlmostEqual(ic.dihed_angle(c[2], c[0], c[3], c[5])[0], angle)
Example #11
0
 def test_volume_error_water(self):
     mol = XYZFile("input/water.xyz").get_molecule()
     vdw_volumes = []
     sas_volumes = []
     ses_volumes = []
     errors = []
     for i in xrange(100):
         vdw_volume, sas_volume, ses_volume, error = estimate_volumes(
             mol, 2.0 * angstrom)
         vdw_volumes.append(vdw_volume)
         sas_volumes.append(sas_volume)
         ses_volumes.append(ses_volume)
         errors.append(error)
     #print "vdw", numpy.mean(vdw_volumes), numpy.std(vdw_volumes), numpy.mean(errors)
     #print "sas", numpy.mean(sas_volumes), numpy.std(sas_volumes), numpy.mean(errors)
     #print "ses", numpy.mean(ses_volumes), numpy.std(ses_volumes), numpy.mean(errors)
     self.assert_(numpy.std(vdw_volumes) < numpy.mean(errors) * 1.5)
     self.assert_(numpy.std(sas_volumes) < numpy.mean(errors) * 1.5)
     self.assert_(numpy.std(ses_volumes) < numpy.mean(errors) * 1.5)
Example #12
0
 def test_bigbox_dinitrogen(self):
     mol = XYZFile("input/dinitrogen.xyz").get_molecule()
     self.check_bigbox(mol)
Example #13
0
 def test_bigbox_water(self):
     mol = XYZFile("input/water.xyz").get_molecule()
     self.check_bigbox(mol)
Example #14
0
 def test_volume_order_dinitrogen(self):
     mol = XYZFile("input/dinitrogen.xyz").get_molecule()
     self.check_volume_order(mol)
Example #15
0
 def test_volume_order_water(self):
     mol = XYZFile("input/water.xyz").get_molecule()
     self.check_volume_order(mol)
 def load_molecule(self, xyz_fn):
     molecule = XYZFile(os.path.join("input", xyz_fn)).get_molecule()
     molecule.graph = MolecularGraph.from_geometry(molecule)
     return molecule
Example #17
0
 def test_volume_argon(self):
     mol = XYZFile("input/argon.xyz").get_molecule()
     vdw_volume, sas_volume, ses_volume, error = estimate_volumes(mol)
     self.assertEqual(vdw_volume, ses_volume)
     self.assert_(sas_volume > vdw_volume)
Example #18
0
 def test_volume_tpa(self):
     mol = XYZFile("input/tpa.xyz").get_molecule()
     vdw_volume, sas_volume, ses_volume, error = estimate_volumes(mol)
     self.assert_(ses_volume > vdw_volume)
     self.assert_(sas_volume > ses_volume)
Example #19
0
 def test_dump(self):
     m = XYZFile("input/thf.xyz").get_molecule()
     psf = PSFFile()
     psf.add_molecule(m)
     psf.write_to_file("output/thf.psf")
Example #20
0
 def yield_test_molecules(self):
     for filename in ["tpa.xyz", "water.xyz", "thf_single.xyz"]:
         molecule = XYZFile(os.path.join("input", filename)).get_molecule()
         molecule.filename = filename
         graph = MolecularGraph.from_geometry(molecule)
         yield molecule, graph
Example #21
0
CC30A = CritAnd(HasAtomNumber(6), HasNeighborNumbers(6,6,6,6))
CC31A = CritAnd(HasAtomNumber(6), HasNeighborNumbers(6,6,6,1))
CC32A = CritAnd(HasAtomNumber(6), HasNeighborNumbers(6,6,1,1))
CC33A = CritAnd(HasAtomNumber(6), HasNeighborNumbers(6,1,1,1))

atom_filters = {
    "CC30A": CC30A,
    "CC31A": CC31A,
    "CC32A": CC32A,
    "CC33A": CC33A,
    "HCA1": CritAnd(HasAtomNumber(1), HasNeighbors(CC31A)),
    "HCA2": CritAnd(HasAtomNumber(1), HasNeighbors(CC32A)),
    "HCA3": CritAnd(HasAtomNumber(1), HasNeighbors(CC33A)),
}

def get_atom_type(index, graph):
    for atom_type, atom_filter in atom_filters.items():
        if atom_filter(index, graph):
            return atom_type
    raise ValueError("Unrecognized atom (index %i)." % index)

args = sys.argv[1:]

molecule = XYZFile(args[0]).get_molecule()
graph = MolecularGraph.from_geometry(molecule)
atom_types = [get_atom_type(index, graph) for index in range(molecule.size)]

psf = PSFFile()
psf.add_molecular_graph(graph, atom_types=atom_types)
psf.write_to_file(args[0].replace(".xyz", ".psf"))
 def load_molecule(self, xyz_fn):
     molecule = XYZFile(os.path.join("input", xyz_fn)).get_molecule()
     molecule.graph = MolecularGraph.from_geometry(molecule)
     return molecule
Example #23
0
 def test_bigbox_argon(self):
     mol = XYZFile("input/argon.xyz").get_molecule()
     self.check_bigbox(mol)
Example #24
0
 def test_bigbox_tpa(self):
     mol = XYZFile("input/tpa.xyz").get_molecule()
     self.check_bigbox(mol)
Example #25
0
 def yield_test_molecules(self):
     for filename in ["tpa.xyz", "water.xyz", "thf_single.xyz"]:
         molecule = XYZFile(os.path.join("input", filename)).get_molecule()
         molecule.filename = filename
         graph = MolecularGraph.from_geometry(molecule)
         yield molecule, graph
Example #26
0
 def test_volume_water(self):
     mol = XYZFile("input/water.xyz").get_molecule()
     vdw_volume, sas_volume, ses_volume, error = estimate_volumes(mol, 1.0)
     self.assert_(ses_volume > vdw_volume)
     self.assert_(sas_volume > ses_volume)
Example #27
0
 def test_radius_water(self):
     mol = XYZFile("input/water.xyz").get_molecule()
     radius, error = estimate_radius(mol)
Example #28
0
    def get_molecules(self):
        tpa = XYZFile("input/tpa.xyz").get_molecule()
        tpa.title = "tpa"
        tea = XYZFile("input/tea.xyz").get_molecule()
        tea.title = "tea"
        water = XYZFile("input/water.xyz").get_molecule()
        water.title = "water"
        cyclopentane = XYZFile("input/cyclopentane.xyz").get_molecule()
        cyclopentane.title = "cyclopentane"

        return [tpa, tea, water, cyclopentane]
Example #29
0
 def load_molecule(self, filename):
     m = XYZFile("input/" + filename).get_molecule()
     return m.coordinates, numpy.array(
         [periodic[number].mass for number in m.numbers], float)