Example #1
0
def get_dynamics(atoms, mcfm_pot, T=300):
    # ------ Set up logfiles
    traj_interval = 10
    thermoPrintstatus_log = open("log_thermoPrintstatus.log", "w")
    outputTrajectory = open("log_trajectory.xyz", "w")
    mcfmError_log = open("log_mcfmError.log", "w")

    # ------ Let optimiser use the base potential and relax the per atom energies
    mcfm_pot.qm_cluster.flagging_module.ema_parameter = 0.1
    mcfm_pot.qm_cluster.flagging_module.qm_flag_potential_energies =\
        np.ones((len(atoms), 2), dtype=float) * 1001

    # ------ Minimize positions
    opt = FIRE(atoms)
    optimTrajectory = open("log_optimizationTrajectory.xyz", "w")
    opt.attach(trajectory_writer, 1, atoms, optimTrajectory, writeResults=True)
    opt.run(fmax=0.05, steps=1000)

    # ------ Define ASE dyamics
    sim_T = T * units.kB
    MaxwellBoltzmannDistribution(atoms, 2 * sim_T)

    timestep = 5e-1 * units.fs
    friction = 1e-2
    dynamics = Langevin(atoms, timestep, sim_T, friction, fixcm=False)
    dynamics.attach(mcfm_thermo_printstatus, 100, 100, dynamics,
                    atoms, mcfm_pot, logfile=thermoPrintstatus_log)
    dynamics.attach(trajectory_writer, traj_interval, atoms, outputTrajectory, writeResults=False)
    dynamics.attach(mcfm_error_logger, 100, 100, dynamics, atoms, mcfm_pot, logfile=mcfmError_log)
    return dynamics
Example #2
0
def minimize_energy(atoms, nstep, pressure_interval=10):
    bulkmodulus = 140e9 / 1e5  # Bulk modulus of typical metal (Cu), in bar.
    dyn = FIRE(atoms)
    unstress = Inhomogeneous_NPTBerendsen(atoms, 50*units.fs, 0,
                                          taup=5000*units.fs,
                                          compressibility=1/bulkmodulus)
    dyn.attach(unstress.scale_positions_and_cell, interval=10)
    dyn.run(steps=nstep)
Example #3
0
def minimize_energy(atoms, nstep, pressure_interval=10):
    bulkmodulus = 140e9 / 1e5  # Bulk modulus of typical metal (Cu), in bar.
    dyn = FIRE(atoms)
    unstress = Inhomogeneous_NPTBerendsen(atoms,
                                          50 * units.fs,
                                          0,
                                          taup=5000 * units.fs,
                                          compressibility=1 / bulkmodulus)
    dyn.attach(unstress.scale_positions_and_cell, interval=10)
    dyn.run(steps=nstep)
def get_dynamics(atoms, mcfm_pot, T=300):
    # ------ Set up logfiles
    traj_interval = 10
    thermoPrintstatus_log = open("log_thermoPrintstatus.log", "w")
    outputTrajectory = open("log_trajectory.xyz", "w")
    mcfmError_log = open("log_mcfmError.log", "w")

    # ------ Let optimiser use the base potential and relax the per atom energies
    mcfm_pot.qm_cluster.flagging_module.ema_parameter = 0.1
    mcfm_pot.qm_cluster.flagging_module.qm_flag_potential_energies =\
        np.ones((len(atoms), 2), dtype=float) * 1001

    # ------ Minimize positions
    opt = FIRE(atoms)
    optimTrajectory = open("log_optimizationTrajectory.xyz", "w")
    opt.attach(trajectory_writer, 1, atoms, optimTrajectory, writeResults=True)
    opt.run(fmax=0.05, steps=1000)

    # ------ Define ASE dyamics
    sim_T = T * units.kB
    MaxwellBoltzmannDistribution(atoms, 2 * sim_T)

    timestep = 5e-1 * units.fs
    friction = 1e-2
    dynamics = Langevin(atoms, timestep, sim_T, friction, fixcm=False)
    dynamics.attach(mcfm_thermo_printstatus,
                    100,
                    100,
                    dynamics,
                    atoms,
                    mcfm_pot,
                    logfile=thermoPrintstatus_log)
    dynamics.attach(trajectory_writer,
                    traj_interval,
                    atoms,
                    outputTrajectory,
                    writeResults=False)
    dynamics.attach(mcfm_error_logger,
                    100,
                    100,
                    dynamics,
                    atoms,
                    mcfm_pot,
                    logfile=mcfmError_log)
    return dynamics
Example #5
0
def relax_structure(atoms, relax_fmax=0.05, traj_interval=None):
    """
    Relax atoms object. If it contains a 'fixed_mask' array, then run constrained relaxation
    """
    arel = atoms.copy()
    try:
        fix_mask = atoms.get_array("fixed_mask")
        print("Running relaxation with %d constrained atoms" % fix_mask.sum())
        const = FixAtoms(mask=fix_mask)
        arel.set_constraint(const)
    except:
        print("No constraints specified, running relaxation")
    arel.set_calculator(calc)
    opt = FIRE(arel)  # LBFGS(arel) #
    if traj_interval is not None:
        from quippy.io import AtomsWriter

        out = AtomsWriter("traj-relax_structure.xyz")
        trajectory_write = lambda: out.write(QAtoms(arel, charge=None))
        opt.attach(trajectory_write, interval=traj_interval)
    opt.run(fmax=relax_fmax)
    return arel
Example #6
0
     images.append(initial.copy())

if restart:
   for j in range(1,intermediate_images+1):
     nebimage=io.read('neb%d.traj' % j)
     nebimage.set_initial_magnetic_moments(mag)
     images.append(nebimage)

images.append(final)

if not climb:
  neb = NEB(images,k=k)
if climb:
  neb = NEB(images,climb=True,k=k)

m.set_neb(neb)

#only for first step, linear interpolation here.
if not restart:
  neb.interpolate()

if not climb:
   qn = FIRE(neb, logfile='qn.log')
if climb:
   qn = FIRE(neb, logfile='qn.log')

for j in range(1,intermediate_images+1):
    traj = io.PickleTrajectory('neb%d.traj' % j, 'a', images[j])
    qn.attach(traj)

qn.run(fmax=0.05)
Example #7
0
    image.constraints.append(constraint)

# Displace last image:
for i in xrange(1, 8, 1):
    images[-1].positions[-i] += (d / 2, -h1 / 3, 0)

write('initial.traj', images[0])
# Relax height of Ag atom for initial and final states:
for image in [images[0], images[-1]]:
    QuasiNewton(image).run(fmax=0.01)

if 0:
    write('initial.pckl', image[0])
    write('finial.pckl', image[-1])
# Interpolate positions between initial and final states:
neb.interpolate()

for image in images:
    print image.positions[-1], image.get_potential_energy()

traj = PickleTrajectory('mep.traj', 'w')

dyn = FIRE(neb, dt=0.1)
#dyn = MDMin(neb, dt=0.1)
#dyn = QuasiNewton(neb)
dyn.attach(neb.writer(traj))
dyn.run(fmax=0.01, steps=150)

for image in images:
    print image.positions[-1], image.get_potential_energy()
Example #8
0
      print 'Running WITH EAM as embedded cluster'
      qm_pot_file  = os.path.join(pot_dir, 'PotBH_fakemod.xml')
      print qm_pot_file
      mm_init_args = 'IP EAM_ErcolAd do_rescale_r=T r_scale=1.01' # Classical potential
      qm_pot       = Potential(mm_init_args, param_filename=qm_pot_file, cutoff_skin=cutoff_skin)
      qmmm_pot     = set_qmmm_pot(atoms, atoms.params['CrackPos'], mm_pot, qm_pot)

    strain_atoms = fix_edges(atoms)

    print 'Setup dynamics'
#If input_file is crack.xyz the cell has not been thermalized yet.
#Otherwise it will recover temperature from the previous run.
    print 'Attaching trajectories to dynamics'
    trajectory = AtomsWriter(traj_file)
#Only wriates trajectory if the system is in the LOTFDynamicas
#Interpolation 
    atoms.wrap()
    atoms.set_cutoff(3.0)
    atoms.calc_connect()
    print 'Running Crack Simulation'
    RELAXATION = False
    if RELAXATION:
      dynamics = FIRE(atoms)
      dynamics.attach(pass_trajectory_context(trajectory, dynamics), traj_interval, dynamics)
      dynamics.run(fmax=0.1)
    else:
      dynamics = LOTFDynamics(atoms, timestep, extrapolate_steps)
      dynamics.attach(pass_trajectory_context(trajectory, dynamics), traj_interval, dynamics)
      nsteps    = 2000
      dynamics.run(nsteps)
Example #9
0
    image.constraints.append(constraint)

# Displace last image:
for i in xrange(1,8,1):
    images[-1].positions[-i] += (d/2, -h1/3, 0)

write('initial.traj', images[0])
# Relax height of Ag atom for initial and final states:
for image in [images[0], images[-1]]:
    QuasiNewton(image).run(fmax=0.01)

if 0:
    write('initial.pckl', image[0])
    write('finial.pckl', image[-1])
# Interpolate positions between initial and final states:
neb.interpolate()

for image in images:
    print image.positions[-1], image.get_potential_energy()

traj = PickleTrajectory('mep.traj', 'w')

dyn = FIRE(neb, dt=0.1)
#dyn = MDMin(neb, dt=0.1)
#dyn = QuasiNewton(neb)
dyn.attach(neb.writer(traj))
dyn.run(fmax=0.01,steps=150)

for image in images:
    print image.positions[-1], image.get_potential_energy()
    number_of_si = 0
    initial_magmom = 0

    for atom in bulk_mat:
        if atom.symbol == 'Fe':
            initial_magmom += 2.2
        else:
            number_of_si += 1.0

    si_concentration = number_of_si / number_of_atoms

    saver = Gpw_save(calc, system_name + '.gpw')
    #Check if there is an existing .traj, if so append
    if os.path.isfile('./' + system_name + '.traj'):
        traj = Trajectory(system_name + '.traj', 'a', bulk_mat)
    else:
        traj = Trajectory(system_name + '.traj', 'w', bulk_mat)
    ucf = UnitCellFilter(bulk_mat)
    relaxer = FIRE(ucf, logfile=system_name + '.txt')
    relaxer.attach(traj)
    relaxer.attach(saver)
    relaxer.run(fmax=0.025)
    bulk_mat.get_potential_energy()

    #Save the final state of the calculations
    if density_number == 5.4:

        calc.write(system_name + '_final.gpw')
        save_atoms(bulk_mat, e_cut, nbands, density_number, smear,
                   initial_magmom, si_concentration, system_id, 0, final_db)
Example #11
0
    qm_pot,
    buffer_width=buff,
    pbc_type=[False, False, False])


def pass_trajectory_context(trajectory, dynamics):
    def traj_writer(dynamics):
        trajectory.write(dynamics.atoms)

    return traj_writer


#Relax atoms around the defect.
trajectory = AtomsWriter('gb_traj_ini.xyz')
opt = FIRE(gb_cell)
opt.attach(pass_trajectory_context(trajectory, opt), 1, opt)
gb_cell.set_calculator(qmmm_pot)
opt.run(fmax=args.force_tolerance)
gb_cell.write('dft_edip_H_relaxed.xyz')

#One shot calculation of forces with defect removed.
gb_cell = AtomsReader('dft_edip_H_relaxed.xyz')[-1]
#Remove defect
defect = find_h_atom(gb_cell)
gb_cell.remove_atoms([defect.index + 1])

x, y, z = gb_cell.positions.T
radius1 = np.sqrt((x - h_pos[0])**2 + (y - h_pos[1])**2 + (z - h_pos[2])**2)
qm_region_mask = (radius1 < qm_radius)
qm_buffer_mask = (radius1 < qm_radius + buff)