Esempio n. 1
0
def equilibrated(asap3, berendsenparams):
    """Make an atomic system with equilibrated temperature and pressure."""
    rng = np.random.RandomState(42)
    with seterr(all='raise'):
        print()
        # Must be big enough to avoid ridiculous fluctuations
        atoms = bulk('Au', cubic=True).repeat((3, 3, 3))
        #a[5].symbol = 'Ag'
        print(atoms)
        atoms.calc = asap3.EMT()
        MaxwellBoltzmannDistribution(atoms,
                                     temperature_K=100,
                                     force_temp=True,
                                     rng=rng)
        Stationary(atoms)
        assert abs(atoms.get_temperature() - 100) < 0.0001
        md = NPTBerendsen(atoms,
                          timestep=20 * fs,
                          logfile='-',
                          loginterval=200,
                          **berendsenparams['npt'])
        # Equilibrate for 20 ps
        md.run(steps=1000)
        T = atoms.get_temperature()
        pres = -atoms.get_stress(
            include_ideal_gas=True)[:3].sum() / 3 / GPa * 10000
        print("Temperature: {:.2f} K    Pressure: {:.2f} bar".format(T, pres))
        return atoms
Esempio n. 2
0
    def __init__(self, atoms, timestep, temperature, taut=0.5e3,
                 pressure=1.01325, taup=1e3,
                 compressibility=4.57e-5, fixcm=True, trajectory=None,
                 **kwargs):

        NPTBerendsen.__init__(self, atoms, timestep, temperature, taut,
                              pressure, taup,
                              compressibility, fixcm, trajectory)

        OTF.__init__(self, **kwargs)

        self.md_engine = 'NPTBerendsen'
Esempio n. 3
0
    def testWithNumericalStressWithPBCEnabled(self):
        # Run NPT dynamics for some steps and periodically check that the
        # numerical and analytical stresses agree up to a given
        # absolute difference
        filename = os.path.join(
            path, '../tools/generate-unit-test-expect/others/Benzene.json')
        benzene = read(filename)
        # set velocities to a very small value to avoid division by zero
        # warning due to initial zero temperature.
        #
        # Note that there are 4 benzene molecules, thus, 48 atoms in
        # Benzene.json
        benzene.set_velocities(np.full((48, 3), 1e-15))
        calculator = self.model.ase()
        benzene.set_calculator(calculator)
        dyn = NPTBerendsen(benzene,
                           timestep=0.1 * units.fs,
                           temperature=300 * units.kB,
                           taut=0.1 * 1000 * units.fs,
                           pressure=1.01325,
                           taup=1.0 * 1000 * units.fs,
                           compressibility=4.57e-5)

        def test_stress():
            stress = benzene.get_stress()
            numerical_stress = calculator.calculate_numerical_stress(benzene)
            self.assertEqual(stress, numerical_stress)

        dyn.attach(test_stress, interval=30)
        dyn.run(120)
Esempio n. 4
0
    def testWithNumericalStressWithPBCEnabled(self):
        filename = os.path.join(path, '../tools/generate-unit-test-expect/others/Benzene.cif')
        benzene = read(filename)
        calculator = self.model.ase()
        benzene.set_calculator(calculator)
        dyn = NPTBerendsen(benzene, timestep=0.1 * units.fs,
                           temperature=300 * units.kB,
                           taut=0.1 * 1000 * units.fs, pressure=1.01325,
                           taup=1.0 * 1000 * units.fs, compressibility=4.57e-5)

        def test_stress():
            stress = benzene.get_stress()
            numerical_stress = calculator.calculate_numerical_stress(benzene)
            diff = torch.from_numpy(stress - numerical_stress).abs().max().item()
            self.assertLess(diff, tol)
        dyn.attach(test_stress, interval=30)
        dyn.run(120)