Exemplo n.º 1
0
    def test_velocities(self):
        si = 14
        coords = list()
        coords.append([0, 0, 0])
        coords.append([0.75, 0.5, 0.75])

        # Silicon structure for testing.
        latt = [[3.8401979337, 0.00, 0.00],
                [1.9200989668, 3.3257101909, 0.00],
                [0.00, -2.2171384943, 3.1355090603]]
        struct = Structure(latt, [si, si], coords)
        poscar = Poscar(struct)
        poscar.set_temperature(900)

        v = np.array(poscar.velocities)

        for x in np.sum(v, axis=0):
            self.assertAlmostEqual(x, 0, 7)

        temperature = struct[0].specie.atomic_mass.to("kg") * \
                      np.sum(v ** 2) / (3 * const.k) * 1e10
        self.assertAlmostEqual(temperature, 900, 4,
                               'Temperature instantiated incorrectly')

        poscar.set_temperature(700)
        v = np.array(poscar.velocities)
        for x in np.sum(v, axis=0):
            self.assertAlmostEqual(
                x, 0, 7, 'Velocities initialized with a net momentum')

        temperature = struct[0].specie.atomic_mass.to("kg") * \
                      np.sum(v ** 2) / (3 * const.k) * 1e10
        self.assertAlmostEqual(temperature, 700, 4,
                               'Temperature instantiated incorrectly')
Exemplo n.º 2
0
    def test_velocities(self):
        si = 14
        coords = list()
        coords.append([0, 0, 0])
        coords.append([0.75, 0.5, 0.75])

        # Silicon structure for testing.
        latt = [[3.8401979337, 0.00, 0.00], [1.9200989668, 3.3257101909, 0.00],
                [0.00, -2.2171384943, 3.1355090603]]
        struct = Structure(latt, [si, si], coords)
        poscar = Poscar(struct)
        poscar.set_temperature(900)

        v = np.array(poscar.velocities)

        for x in np.sum(v, axis=0):
            self.assertAlmostEqual(x, 0, 7)

        temperature = struct[0].specie.atomic_mass.to("kg") * \
                      np.sum(v ** 2) / (3 * const.k) * 1e10
        self.assertAlmostEqual(temperature, 900, 4,
                               'Temperature instantiated incorrectly')

        poscar.set_temperature(700)
        v = np.array(poscar.velocities)
        for x in np.sum(v, axis=0):
            self.assertAlmostEqual(
                x, 0, 7, 'Velocities initialized with a net momentum')

        temperature = struct[0].specie.atomic_mass.to("kg") * \
                      np.sum(v ** 2) / (3 * const.k) * 1e10
        self.assertAlmostEqual(temperature, 700, 4,
                               'Temperature instantiated incorrectly')
Exemplo n.º 3
0
 def validate_and_initialize(cls):
     """
     Initialize new Poscar instance from given user inputs
     """
     # complete the parameters list accepted by the pymatgen Poscar
     # object (Checking for correct types is delegated to the pymatgen
     # Poscar constructor!)
     valid_poscar_kwargs = {
         'structure': cls.structure_from_input(),
         'comment': None,  # do not add any comments
         'selective_dynamics': cls.input_constraints,
         'true_names': True,  # always assume true species names
         'velocities': cls.input_velocities,
         'predictor_corrector': None,  # leave predictor-corrector unset
         'predictor_corrector_preamble': None,
         'sort_structure': True,  # always sort structure
     }
     # initilize the Poscar instance
     poscar_object = Poscar(**valid_poscar_kwargs)
     # if temperature is given initialize the atomic velocities accordingly
     if cls.input_temperature is not None:
         # pymatgen initialization from temperature cannot handle structures
         # with only one atom. Check structure length to avoid the AiiDA
         # error triggered by the resulting `nan` values
         if len(cls.structure_from_input()) <= 1:
             raise PoscarWrapperError("Initialization of velocities from "
                                      "temperature only possible for "
                                      "structures containing at least two "
                                      "atoms")
         # pymatgen happily accepts any temperature value below 0.0 K and
         # initialized to `nan`
         if cls.input_temperature < 0.0:
             raise PoscarWrapperError("Given temperature must not "
                                      "be smaller than zero (set value: "
                                      "'{}')".format(cls.input_temperature))
         poscar_object.set_temperature(cls.input_temperature)
     return poscar_object