def test_md(factory): # XXX ugly hack ver = factory.factory.version() if LooseVersion(ver) < '3.8': pytest.skip('No stress tensor until openmx 3.8+') bud = Atoms('CH4', np.array([[0.000000, 0.000000, 0.100000], [0.682793, 0.682793, 0.682793], [-0.682793, -0.682793, 0.68279], [-0.682793, 0.682793, -0.682793], [0.682793, -0.682793, -0.682793]]), cell=[10, 10, 10]) calc = factory.calc( label='ch4', xc='GGA', energy_cutoff=300 * Ry, convergence=1e-4 * Ha, # Use 'C_PBE19' and 'H_PBE19' for version 3.9 definition_of_atomic_species=[['C', 'C5.0-s1p1', 'C_PBE13'], ['H', 'H5.0-s1', 'H_PBE13']], kpts=(1, 1, 1), eigensolver='Band') bud.calc = calc with Trajectory('example.traj', 'w', bud) as traj: ucf = UnitCellFilter(bud, mask=[True, True, False, False, False, False]) dyn = QuasiNewton(ucf) dyn.attach(traj.write) dyn.run(fmax=0.1) bud.get_potential_energy()
def test_example(): from ase import Atoms from ase.constraints import FixAtoms from ase.io import Trajectory from ase.optimize import QuasiNewton from ase.calculators.morse import MorsePotential atoms = Atoms('H7', positions=[(0, 0, 0), (1, 0, 0), (0, 1, 0), (1, 1, 0), (0, 2, 0), (1, 2, 0), (0.5, 0.5, 1)], constraint=[FixAtoms(range(6))], calculator=MorsePotential()) traj = Trajectory('H.traj', 'w', atoms) dyn = QuasiNewton(atoms, maxstep=0.2) dyn.attach(traj.write) dyn.run(fmax=0.01, steps=100) print(atoms) del atoms[-1] print(atoms) del atoms[5] print(atoms) assert len(atoms.constraints[0].index) == 5
def test_md(): import numpy as np import unittest from ase.units import Ry, Ha from ase.calculators.openmx import OpenMX from ase.io.trajectory import Trajectory from ase.optimize import QuasiNewton from ase.constraints import UnitCellFilter from ase.calculators.calculator import PropertyNotImplementedError from ase import Atoms """ Only OpenMX 3.8 or higher version pass this test""" bud = Atoms('CH4', np.array([ [0.000000, 0.000000, 0.100000], [0.682793, 0.682793, 0.682793], [-0.682793, -0.682793, 0.68279], [-0.682793, 0.682793, -0.682793], [0.682793, -0.682793, -0.682793]]), cell=[10, 10, 10]) calc = OpenMX( label='ch4', xc='GGA', energy_cutoff=300 * Ry, convergence=1e-4 * Ha, # Use 'C_PBE19' and 'H_PBE19' for version 3.9 definition_of_atomic_species=[['C', 'C5.0-s1p1', 'C_PBE13'], ['H', 'H5.0-s1', 'H_PBE13']], kpts=(4, 4, 4), eigensolver='Band' ) bud.set_calculator(calc) try: bud.get_stress() except PropertyNotImplementedError as err: raise unittest.SkipTest(err) traj = Trajectory('example.traj', 'w', bud) ucf = UnitCellFilter(bud, mask=[True, True, False, False, False, False]) dyn = QuasiNewton(ucf) dyn.attach(traj.write) dyn.run(fmax=0.1) bud.get_potential_energy() # XXX maybe assert something? traj.close()
def test_example(testdir): atoms = Atoms('H7', positions=[(0, 0, 0), (1, 0, 0), (0, 1, 0), (1, 1, 0), (0, 2, 0), (1, 2, 0), (0.5, 0.5, 1)], constraint=[FixAtoms(range(6))], calculator=MorsePotential()) with Trajectory('H.traj', 'w', atoms) as traj: dyn = QuasiNewton(atoms, maxstep=0.2) dyn.attach(traj.write) dyn.run(fmax=0.01, steps=100) print(atoms) del atoms[-1] print(atoms) del atoms[5] print(atoms) assert len(atoms.constraints[0].index) == 5
from ase import Atoms from ase.constraints import FixAtoms from ase.io import Trajectory, read from ase.neb import NEB, NEBTools from ase.calculators.morse import MorsePotential from ase.optimize import BFGS, QuasiNewton atoms = Atoms('H7', positions=[(0, 0, 0), (1, 0, 0), (0, 1, 0), (1, 1, 0), (0, 2, 0), (1, 2, 0), (0.5, 0.5, 1)], constraint=[FixAtoms(range(6))], calculator=MorsePotential()) traj = Trajectory('H.traj', 'w', atoms) dyn = QuasiNewton(atoms, maxstep=0.2) dyn.attach(traj.write) dyn.run(fmax=0.01, steps=100) print(atoms) del atoms[-1] print(atoms) del atoms[5] print(atoms) assert len(atoms.constraints[0].index) == 5 fmax = 0.05 nimages = 3 print([a.get_potential_energy() for a in Trajectory('H.traj')]) images = [Trajectory('H.traj')[-1]] for i in range(nimages):
from ase.optimize import BFGS, QuasiNewton atoms = Atoms('H7', positions=[(0, 0, 0), (1, 0, 0), (0, 1, 0), (1, 1, 0), (0, 2, 0), (1, 2, 0), (0.5, 0.5, 1)], constraint=[FixAtoms(range(6))], calculator=MorsePotential()) traj = Trajectory('H.traj', 'w', atoms) dyn = QuasiNewton(atoms, maxstep=0.2) dyn.attach(traj.write) dyn.run(fmax=0.01, steps=100) print(atoms) del atoms[-1] print(atoms) del atoms[5] print(atoms) assert len(atoms.constraints[0].index) == 5 fmax = 0.05 nimages = 3
now = time.time() if maxtime - (now - starttime) / 3600. < avg_iter: traj.write() if rank == 0: open('auto_restart', 'a').write("Run %i ended on " % (run) + time.strftime('%m/%d/%Y\t%H:%M:%S') + " after %4.2f hours" % ((now - starttime) / 3600.) + '\n') os.system(restart_command) sys.exit() #################################### qn.attach(traj) qn.attach(StopCalc) starttime = time.time() if run > 0: qn.replay_trajectory('qn.traj') qn.run(fmax=0.05) pdos.pdos(atoms, outdir='outdir', spinpol=False, save_pkl=save_pdos_pkl, Emin=-20, Emax=20, kpts=(kpts[0] * 3, kpts[1] * 3, 1), DeltaE=0.01,
for i in range(3): ranks = range(i * n, (i + 1) * n) image = initial.copy() if rank in ranks: calc = GPAW(h=0.3, kpts=(2, 2, 1), txt='neb%d.txt' % j, communicator=ranks) image.set_calculator(calc) image.set_constraint(constraint) images.append(image) images.append(final) neb = NEB(images, parallel=True, climb=True) neb.interpolate() qn = BFGS(neb, logfile='qn.log') traj = Trajectory('neb%d.traj' % j, 'w', images[j], master=(rank % n == 0)) qn.attach(traj) qn.run(fmax=0.05)
# OP_f_text = np.savetxt('out.tmp', OP_f) # OP_f_infile = open('out.tmp','r') # OP_f_text = OP_f_infile.read() # text_file.write(OP_f_text) # text_file.close() # exit() x_dist = a.get_distance(a0 = 0, a1 = 1) OP.append(x_dist) epot = a.get_potential_energy() / len(a) ekin = a.get_kinetic_energy() / len(a) ETOT = epot+ekin OP.append(ETOT) qn = QuasiNewton(atoms, trajectory='qn.traj') qn.attach(print_distance) qn.run(fmax=0.001) qn.attach(print_distance) write('qn.final.xyz', atoms) # Set the momenta corresponding to T=300K MaxwellBoltzmannDistribution(atoms, 300*units.kB) print 'Removing linear momentum and angular momentum' Stationary(atoms) # zero linear momentum ZeroRotation(atoms) # zero angular momentum # We want to run MD using the VelocityVerlet algorithm. dyn = VelocityVerlet(atoms, 0.1*units.fs, trajectory='moldyn4.traj') # save trajectory. #Function to print the potential, kinetic and total energy. def printenergy(t=atoms): #store a reference to atoms in the definition.
constraint = FixAtoms(indices=indices) slab.set_constraint(constraint) dyn = QuasiNewton(slab) dyn.run(fmax=0.05) Z = slab.get_positions()[:, 2] print Z[0] - Z[1] print Z[1] - Z[2] print Z[2] - Z[3] b = 1.2 h = 2.0 slab += Atom('C', (d, 2 * y / 3, h)) slab += Atom('O', (3 * d / 2, y / 3, h)) traj = PickleTrajectory('initial.traj', 'w', slab) dyn = QuasiNewton(slab) dyn.attach(traj.write) dyn.run(fmax=0.05) #view(slab) # Make band: images = [slab.copy() for i in range(6)] neb = NEB(images, climb=True) # Set constraints and calculator: for image in images: image.set_calculator(EMT()) image.set_constraint(constraint) # Displace last image: images[-1].positions[-1] = (2 * d, 2 * y / 3, h) traj = PickleTrajectory('final.traj', 'w', images[-1]) dyn = QuasiNewton(images[-1])
Hamiltonian_MaxAngularMomentum_='', Hamiltonian_MaxAngularMomentum_H='"s"', )) c = Hookean_Always(a1=0, a2=1, k=0, rt=0.6) atoms.set_constraint(c) OP = [] def print_distance(a=atoms): distance = a.get_distance(a0=0,a1=1) OP.append(distance) epot = a.get_potential_energy() / len(a) ekin = a.get_kinetic_energy() / len(a) ETOT = epot+ekin OP.append(ETOT) dyn = QuasiNewton(atoms, trajectory='atoms.traj') dyn.attach(print_distance) dyn.run(steps=10) print atoms.get_distance(a0=0, a1=1) write('test.final.xyz', atoms) OP_f = [OP[i:i+2] for i in xrange(0,len(OP),2)] OP_f_text = np.savetxt('out.tmp', OP_f) # reads array and saves into a file as a string OP_f_infile = open('out.tmp','r') # open file to write string array onto OP_f_text = OP_f_infile.read() text_file.write(OP_f_text) text_file.close()
constraint = FixAtoms(indices=indices) slab.set_constraint(constraint) dyn = QuasiNewton(slab) dyn.run(fmax=0.05) Z = slab.get_positions()[:, 2] print Z[0] - Z[1] print Z[1] - Z[2] print Z[2] - Z[3] b = 1.2 h = 2.0 slab += Atom('C', (d, 2 * y / 3, h)) slab += Atom('O', (3 * d / 2, y / 3, h)) traj = PickleTrajectory('initial.traj', 'w', slab) dyn = QuasiNewton(slab) dyn.attach(traj.write) dyn.run(fmax=0.05) #view(slab) # Make band: images = [slab.copy() for i in range(6)] neb = NEB(images, climb=True) # Set constraints and calculator: for image in images: image.set_calculator(EMT()) image.set_constraint(constraint) # Displace last image: images[-1].positions[-1] = (2 * d, 2 * y / 3, h) traj = PickleTrajectory('final.traj', 'w', images[-1]) dyn = QuasiNewton(images[-1])
atoms, outdir='outdir', spinpol=True) #update magmom from pdos for helping in calc restart traj.write() if rank == 0: open('auto_restart', 'a').write("Run %i ended on " % (run) + time.strftime('%m/%d/%Y\t%H:%M:%S') + " after %4.2f hours" % ((now - starttime) / 3600.) + '\n') os.system(restart_command) sys.exit() #################################### qn.attach(estimate_magmom) qn.attach(traj) qn.attach(StopCalc) starttime = time.time() if run > 0: qn.replay_trajectory('qn.traj') qn.run(fmax=0.05) pdos.pdos(atoms, outdir='outdir', spinpol=True, save_pkl=save_pdos_pkl, Emin=-20, Emax=20, kpts=(kpts[0] * 3, kpts[1] * 3, 1),
for i in range(3): ranks = np.arange(i * n, (i + 1) * n) image = initial.copy() if rank in ranks: calc = GPAW(h=0.3, kpts=(2, 2, 1), txt='neb%d.txt' % j, communicator=ranks) image.set_calculator(calc) image.set_constraint(constraint) images.append(image) images.append(final) neb = NEB(images, parallel=True) neb.interpolate() qn = QuasiNewton(neb, logfile='qn.log') traj = PickleTrajectory('neb%d.traj' % j, 'w', images[j], master=(rank % n == 0)) qn.attach(traj) qn.run(fmax=0.05)