Created
March 20, 2019 03:20
-
-
Save leelasd/d44d52b93db79de248d989c963a0b82c to your computer and use it in GitHub Desktop.
NVT of molecule with DFTB using ASE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Demonstrates molecular dynamics with constant energy.""" | |
from ase.lattice.cubic import FaceCenteredCubic | |
from ase.md.velocitydistribution import MaxwellBoltzmannDistribution | |
from ase.md.verlet import VelocityVerlet | |
from ase.md.langevin import Langevin | |
from ase.calculators.dftb import Dftb | |
from ase.optimize import QuasiNewton,fire,gpmin,mdmin,LBFGS | |
from ase.io import write,read | |
from ase.build import molecule | |
from rdkit import Chem | |
from rdkit.Chem import AllChem | |
from ase.optimize.minimahopping import MinimaHopping | |
from ase import * | |
from ase.optimize.basin import BasinHopping | |
from ase.md.velocitydistribution import MaxwellBoltzmannDistribution | |
from ase.io.trajectory import Trajectory | |
from ase import units | |
# Set the momenta corresponding to T=300K | |
atoms = read('trail.mol') | |
atoms.set_calculator(Dftb(label='h2o', | |
atoms=atoms, | |
Hamiltonian_MaxAngularMomentum_='', | |
Hamiltonian_MaxAngularMomentum_C='"p"', | |
Hamiltonian_MaxAngularMomentum_N='"p"', | |
Hamiltonian_MaxAngularMomentum_O='"p"', | |
Hamiltonian_MaxAngularMomentum_H='"s"', | |
)) | |
MaxwellBoltzmannDistribution(atoms, 300 * units.kB) | |
# We want to run MD with constant energy using the Langevin algorithm | |
# with a time step of 5 fs, the temperature T and the friction | |
# coefficient to 0.02 atomic units. | |
T = 300 | |
dyn = Langevin(atoms, 1 * units.fs, T * units.kB, 0.002) | |
def printenergy(a=atoms): # store a reference to atoms in the definition. | |
"""Function to print the potential, kinetic and total energy.""" | |
epot = a.get_potential_energy() / len(a) | |
ekin = a.get_kinetic_energy() / len(a) | |
print('Energy per atom: Epot = %.3feV Ekin = %.3feV (T=%3.0fK) ' | |
'Etot = %.3feV' % (epot, ekin, ekin / (1.5 * units.kB), epot + ekin)) | |
dyn.attach(printenergy, interval=50) | |
# We also want to save the positions of all atoms after every 100th time step. | |
traj = Trajectory('moldyn3.traj', 'w', atoms) | |
dyn.attach(traj.write, interval=50) | |
# Now run the dynamics | |
printenergy() | |
dyn.run(5000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment