Example #1
0
    def test_read_pos_force_energy(self):
        test_in = 'OUTCAR.21'

        g_pos = np.array([2.26725, 2.36995, 0.06367])
        g_force = np.array([-0.171492, -0.290427, -1.773642])
        g_energy = -306.41169589

        parser = Parser(test_in)
        self.assertIsNotNone(parser.build_configurations(1000), 'does not build iterator')

        nr_of_configs = len(list(parser.build_configurations(1000)))
        self.assertEqual(nr_of_configs, 1, 'does not return at least one config')
        nr_of_configs = len(list(parser.build_configurations(1)))
        self.assertEqual(nr_of_configs, 1000, 'does not return the correct number of configs')

        for energy, position, force in parser.build_configurations(1000):
            self.assertTrue(np.array_equal(position[0], g_pos), 'returns wrong position')
            self.assertTrue(np.array_equal(force[0], g_force), 'returns wrong force')
            self.assertEqual(energy, g_energy, 'returns wrong energy')
Example #2
0
    def test_offset(self):
        test_in = 'OUTCAR.21'
        ref_pos = np.array([2.23782, 2.37638, 0.06997])
        ref_force = np.array([-0.130492, -0.307476, -1.951215])
        ref_energy = -306.56723878

        parser = Parser(test_in)

        for energy, pos, force in parser.build_configurations(10000,1):
            self.assertEqual(energy, ref_energy)
            self.assertTrue(np.array_equal(ref_pos, pos[0]))
            self.assertTrue(np.array_equal(ref_force, force[0]))
Example #3
0
def load_data(u_conf: dict, offset=0) -> (int, int, np.array, list):
    '''
    Loads the data from the file specified in u_conf and returns the parameters of the
    simulation as (N_conf, N_ion, lattice vectors, list of configurations).
    '''
    # load parser and save nr of ions and lattice vectors
    parser = Parser(u_conf['file_in'])
    lattice_vectors = parser.find_lattice_vectors()
    lat_consts = np.diag(lattice_vectors.dot(lattice_vectors.T))

    # check if lattice constant is bigger than 2 rcut
    if any(np.greater(2 * u_conf["cutoff"], lat_consts)):
        raise ValueError(
            'Cutoff cannot be bigger than half the lattice constants')

    # build the configurations from the parser
    configurations = [
        Configuration(position, energy, force)
        for (energy, position,
             force) in parser.build_configurations(u_conf['stepsize'], offset)
    ]

    return (len(configurations), parser.find_ion_nr(), lattice_vectors,
            configurations)