def testForceAgainstDefaultNeighborList(self): atoms = Diamond(symbol="C", pbc=False) builtin = torchani.neurochem.Builtins() calculator = torchani.ase.Calculator(builtin.species, builtin.aev_computer, builtin.models, builtin.energy_shifter) default_neighborlist_calculator = torchani.ase.Calculator( builtin.species, builtin.aev_computer, builtin.models, builtin.energy_shifter, True) atoms.set_calculator(calculator) dyn = Langevin(atoms, 5 * units.fs, 50 * units.kB, 0.002) def test_energy(a=atoms): a = a.copy() a.set_calculator(calculator) e1 = a.get_potential_energy() a.set_calculator(default_neighborlist_calculator) e2 = a.get_potential_energy() self.assertLess(abs(e1 - e2), tol) dyn.attach(test_energy, interval=1) dyn.run(500)
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
def smash_it(system): """Run a simple NVT molecular dynamics simulation for 0.1 ps at 200 k using the effective medium theory on a supplied system. Parameters ---------- system : `ase.Atoms` The system that is to be simulated. Returns ------- traj : `list` [`ase.Atoms`] A list of `ase.Atoms` objects comprising the system's trajectory. """ # Tell the system to use the EMT calculator system.set_calculator(EMT()) # Set up the NVT simulation using the Langevin thermostat dyn = Langevin(system, 0.01 * units.fs, 200 * units.kB, 0.002) # Create a list to hold the trajectory & a function to populate it traj = [] def update_traj(a=system): traj.append(a.copy()) # Attach the trajectory populator dyn.attach(update_traj, interval=10) # Run the molecular dynamics simulation from 10000 steps dyn.run(10000) # Return the trajectory return traj
def run_md(self, f, Tmax, steps, n_steps, nmfile=None, displacement=0, min_steps=0, sig=0.34, t=0.1, nm=0, record=False): X, S, Na, cm = hdt.readxyz2(f) if nmfile != None: mode=self.get_mode(nmfile, Na, mn=nm) X=X+mode*np.random.uniform(-displacement,displacement) X=X[0] mol=Atoms(symbols=S, positions=X) mol.set_calculator(ANIENS(self.net,sdmx=20000000.0)) f=os.path.basename(f) T_eff = float(random.randrange(5, Tmax, 1)) # random T (random velocities) from 0K to TK minstep_eff = float(random.randrange(1, min_steps, 1)) # random T (random velocities) from 0K to TK dyn = Langevin(mol, t * units.fs, T_eff * units.kB, 0.01) MaxwellBoltzmannDistribution(mol, T_eff * units.kB) # steps=10000 #10000=1picosecond #Max number of steps to run # n_steps = 1 #Number of steps to run for before checking the standard deviation hsdt_Na=[] evkcal=hdt.evtokcal if record==True: #Records the coordinates at every step of the dynamics fname = f + '_record_' + str(T_eff) + 'K' + '.xyz' #name of file to store coodinated in def printenergy(name=fname, a=mol): """Function to print the potential, kinetic and total energy.""" fil= open(name,'a') Na=a.get_number_of_atoms() c = a.get_positions(wrap=True) fil.write('%s \n comment \n' %Na) for j, i in zip(a, c): fil.write(str(j.symbol) + ' ' + str(i[0]) + ' ' + str(i[1]) + ' ' + str(i[2]) + '\n') fil.close() dyn.attach(printenergy, interval=1) e=mol.get_potential_energy() #Calculate the energy of the molecule. Must be done to get the standard deviation s=mol.calc.stddev stddev = 0 tot_steps = 0 failed = False while (tot_steps <= steps): if stddev > sig and tot_steps > minstep_eff: #Check the standard deviation self.hstd.append(stddev) c = mol.get_positions() s = mol.get_chemical_symbols() Na=mol.get_number_of_atoms() self.Na_train.append(Na) self.coor_train.append(c) self.S_train.append(s) failed=True break else: #if the standard deviation is low, run dynamics, then check it again tot_steps = tot_steps + n_steps dyn.run(n_steps) stddev = evkcal*mol.calc.stddev c = mol.get_positions() s = mol.get_chemical_symbols() e=mol.get_potential_energy() #print("{0:.2f}".format(tot_steps*t),':',"{0:.2f}".format(stddev),':',"{0:.2f}".format(evkcal*e)) return c, s, tot_steps*t, stddev, failed, T_eff
def run_md(atoms, md_temperature = 1000*kB, md_step_size = 1*fs, md_steps=100, md_interval=100, friction=0.02): natoms=atoms.get_number_of_atoms() #atoms.set_calculator(self.opt_calculator) atoms_md = [] e_log = [] atoms_md.append(atoms.copy()) MaxwellBoltzmannDistribution(atoms=atoms, temp=md_temperature) dyn = Langevin(atoms, md_step_size, md_temperature, friction) def md_log(atoms=atoms): atoms_md.append(atoms.copy()) epot=atoms.get_potential_energy() ekin=atoms.get_kinetic_energy() temp = ekin / (1.5 * kB * natoms) e_log.append([epot, ekin, temp]) traj = Trajectory('Au_md.traj', 'w', atoms) # Output MD trajectory before it is treatment dyn.attach(traj.write, interval=10) dyn.attach(md_log, interval=md_interval) dyn.run(md_steps) return atoms_md, e_log
def md_calculation(fcp_file): from ase import units from ase.io.trajectory import Trajectory from ase.md.velocitydistribution import MaxwellBoltzmannDistribution from ase.md.langevin import Langevin from ase.md import MDLogger if 'fcc' in fcp_file: ref_cell = read(ref_fcc) P = np.array([[-1, 1, 1], [1, -1, 1], [1, 1, -1]]) P *= 3 atoms = make_supercell(ref_cell, P) else: raise ValueError("Unknown phase") fcp = ForceConstantPotential.read(fcp_file) fcs = fcp.get_force_constants(atoms) calc = ForceConstantCalculator(fcs) atoms.set_calculator(calc) temperature = 200 number_of_MD_steps = 100 time_step = 5 # in fs dump_interval = 10 traj_file = "data/md_" + fcp_file.split('.')[0] + '{}.traj'.format( temperature) log_file = "data/md_log_{}.log".format(temperature) dyn = Langevin(atoms, time_step * units.fs, temperature * units.kB, 0.02) logger = MDLogger(dyn, atoms, log_file, header=True, stress=False, peratom=True, mode='w') traj_writer = Trajectory(traj_file, 'w', atoms) dyn.attach(logger, interval=dump_interval) dyn.attach(traj_writer.write, interval=dump_interval) # run MD MaxwellBoltzmannDistribution(atoms, temperature * units.kB) dyn.run(number_of_MD_steps)
def test_usage(self): atoms = fcc111('Al', size=(4, 4, 9), orthogonal=True) atoms.set_pbc(True) atoms.center(axis=2, vacuum=10.0) z = atoms.positions[:, 2] top_mask = z > z[115] - 0.1 bottom_mask = z < z[19] + 0.1 calc = EMT() atoms.calc = calc damping = pc.AutoDamping(C11=500 * GPa, p_c=0.2) Pdir = 2 vdir = 0 P = 5 * GPa v = 100.0 * m / s dt = 1.0 * fs T = 400.0 t_langevin = 75 * fs gamma_langevin = 1. / t_langevin slider = pc.SlideWithNormalPressureCuboidCell(top_mask, bottom_mask, Pdir, P, vdir, v, damping) atoms.set_constraint(slider) MaxwellBoltzmannDistribution(atoms, 2 * kB * T) atoms.arrays['momenta'][top_mask, :] = 0 atoms.arrays['momenta'][bottom_mask, :] = 0 handle = StringIO() beginning = handle.tell() temps = np.zeros((len(atoms), 3)) temps[slider.middle_mask, slider.Tdir] = kB * T gammas = np.zeros((len(atoms), 3)) gammas[slider.middle_mask, slider.Tdir] = gamma_langevin integrator = Langevin(atoms, dt, temps, gammas, fixcm=False) logger = pc.SlideLogger(handle, atoms, slider, integrator) logger.write_header() logger() images = [] integrator.attach(logger) integrator.attach(lambda: images.append(atoms.copy())) integrator.run(50) handle.seek(beginning) pc.SlideLog(handle) handle.close()
def md_run(origin_poscar_path, index): print('%d' % index + ' In directory : %s' % origin_poscar_path) atoms = read(origin_poscar_path) calc = ANNCalculator(potentials={ "Ga": "Ga.10t-10t.nn", "N": "N.10t-10t.nn" }) atoms.set_calculator(calc) MaxwellBoltzmannDistribution(atoms, 1200 * kB) Stationary(atoms) md = NVT(atoms, timestep=2 * fs, temperature=1000 * kB, friction=0.05) logger = MDLogger(md, atoms, '-', stress=True) md.attach(logger, interval=1) traj = Trajectory( "nvt_%s.traj" % (origin_poscar_path.split('/')[-1].split('.xsf')[0]), "w", atoms) md.attach(traj.write, interval=200) md.run(40000)
def MD(): old_stdout = sys.stdout sys.stdout = mystdout = StringIO() orig_stdout = sys.stdout f = open('out.txt', 'w') sys.stdout = f #f = open('out_' + str(temp) + '.txt', 'w') #sys.stdout = f Tmin = 1000 Tmax = 15000 a0 = 5.43 N = 1 atoms = Diamond(symbol='Si', latticeconstant=a0) atoms *= (N, N, N) atoms.set_calculator(model.calculator) MaxwellBoltzmannDistribution(atoms, Tmin * units.kB) ###is this allowed? Stationary(atoms) # zero linear momentum ZeroRotation(atoms) def printenergy(a=atoms): epot = a.get_potential_energy() / len(a) ekin = a.get_kinetic_energy() / len(a) print(ekin) traj = Trajectory('Si.traj', 'w', atoms) for temp in np.linspace(Tmin, Tmax, 5): dyn = Langevin(atoms, 5 * units.fs, units.kB * temp, 0.002) dyn.attach(traj.write, interval=1) dyn.attach(printenergy, interval=1) dyn.run(100) sys.stdout = orig_stdout f.close()
bottom_mask = np.loadtxt("bottom_mask.txt").astype(bool) top_mask = np.loadtxt("top_mask.txt").astype(bool) damp = pc.AutoDamping(C11, p_c) slider = pc.SlideWithNormalPressureCuboidCell(top_mask, bottom_mask, Pdir, P, vdir, v, damp) atoms.set_constraint(slider) calc = ASE_CALCULATOR_OBJECT # put a specific calculator here atoms.set_calculator(calc) temps = np.zeros((len(atoms), 3)) temps[slider.middle_mask, slider.Tdir] = kB * T gammas = np.zeros((len(atoms), 3)) gammas[slider.middle_mask, slider.Tdir] = gamma_langevin integrator = Langevin(atoms, dt, temps, gammas, fixcm=False) trajectory = Trajectory('slide.traj', 'a', atoms) # append with open('log_slide.txt', 'r', encoding='utf-8') as log_handle: step_offset = pc.SlideLog(log_handle).step[-1] log_handle = open('log_slide.txt', 'a', 1, encoding='utf-8') # line buffered append logger = pc.SlideLogger(log_handle, atoms, slider, integrator, step_offset) integrator.attach(logger) integrator.attach(trajectory) integrator.run(steps_integrate) log_handle.close() trajectory.close()
size=(size, size, size), pbc=True, latticeconstant=3.5646) view(atoms) atoms.set_calculator(calc) # MaxwellBoltzmannDistribution(atoms, 300 * units.kB) # dyn = VelocityVerlet(atoms, 5 * units.fs) T = 10 dyn = Langevin(atoms, 5 * units.fs, T * units.kB, 0.002) traj = Trajectory('md.traj', 'w', atoms) dyn.attach(traj.write, interval=50) def printenergy(a): """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)) printenergy(atoms) for i in range(200): dyn.run(50) printenergy(atoms)
# os.makedirs(dumpVASP) kspacing = 0.2 steps = 10 temp = 300 struc = bulk("Si", 'diamond', a=5.468728, cubic=True) * (3,3,3) mliap = "potentials/Si-20-20.pth" ff = PyXtal_FF(model={'system': ["Si"]}, logo=False) ff.run(mode='predict', mliap=mliap) calc = PyXtalFFCalculator(ff=ff) struc.set_calculator(calc) #struc.set_calculator(set_vasp('single', kspacing)) #energy, forces = dft_run(struc, path=dumpVASP, ncpu=16, max_time=10) # total energy # MD traj = Trajectory("Si.traj", 'w', struc) MaxwellBoltzmannDistribution(struc, temperature_K=temp+50) # NVT dyn = Langevin(struc, timestep=0.15 * units.fs, temperature_K=temp, friction=0.004 * units.fs) # NPT #dyn = NPT(struc, 1. * units.fs, externalstress=0., ttime=1000*units.fs, pfactor=1000*units.fs, # temperature_K=300) dyn.attach(traj.write, interval=steps) for i in range(1000): dyn.run(steps=steps) PrintEnergy(struc, i) save_to_ASE_db(struc, path=ase_db) traj.close()
if k not in ['energy', 'strain']: del at.info[k] # ***** Setup and run MD ***** # Initialise the dynamical system initial_momenta = at.get_momenta() dynamics = Langevin(at, params.timestep, params.sim_T * units.kB, 8e-4, logfile=log_name) # Save frames to the trajectory every `traj_interval` time steps out = AtomsWriter(traj_name) def trajectory_write(at): atout = at.copy() for k in atout.arrays.keys(): if k not in ['species', 'positions', 'momenta', 'numbers', 'force']: atout.set_array(k, None) for k in atout.info.keys(): if k not in ['energy', 'time', 'temperature', 'pbc', 'Lattice']: del atout.info[k] at.info['energy'] = at.get_potential_energy() out.write(atout) dynamics.attach(trajectory_write, params.traj_interval, at) # Save trajectory
#!simulation outputs numbered, avoids deleting exisiting results iterFile = open("simIteration.txt", 'r+') iteration = int(iterFile.readlines()[0]) + 1 iterFile.seek(0, 0) iterFile.write(str(iteration)) iterFile.close() #!Saving parameter values for each iteration of the simulation logFile = open(".simout/logs/log" + str(iteration) + ".txt", 'w') for p, value in params.p.iteritems(): logFile.write(p + " ==> " + str(value) + "\n") logFile.close crack_pos = [] traj = NetCDFTrajectory('.simout/traj' + str(iteration) + '.nc', 'w', c) dyn.attach(traj.write, 10, dyn.atoms, arrays=['stokes', 'momenta']) dyn.attach(find_crack_tip, 10, dyn.atoms, dt=params.dt * 10, store=True, results=crack_pos) # run for 2000 time steps to reach steady state at initial load for i in range(20): dyn.run(100) if extend_strip(dyn.atoms, params.a, params.N, params.M, params.vacuum): set_constraints(dyn.atoms, params.a) # start decreasing strain #set_constraints(dyn.atoms, params.a, delta_strain=delta_strain)
atoms.set_calculator(mixer) dyn = None if md_style == "Langevin": dyn = Langevin(atoms, timestep, 1.5*T*units.kB, 0.002) elif md_style == "Verlet": dyn = VelocityVerlet(atoms, timestep) elif md_style == "TESTING": dyn = DynTesting(atoms, timestep=0.1*units.fs, offset=(0.1, 0., 0.)) energy_file = None def printenergy(a=atoms): epot = a.get_potential_energy() / len(a) ekin = a.get_kinetic_energy() / len(a) energy_file.write("%.5e,%.5e,%.5e,%.5e" % (epot + ekin, epot, ekin, ekin/(1.5*units.kB)) + "\n") # only enable logging for master node where rank == 0 if rank == 0: energy_file = open("mixer_box_energy.csv", "w+b", buffering=0) energy_file.write("total,potential,kinetic,temperature\n") dyn.attach(printenergy, interval=log_interval) traj = PickleTrajectory(output_file, 'w', atoms) dyn.attach(traj.write, interval=log_interval) printenergy() dyn.run(steps)
d = 2.934 for R in r0list: print 'radius',R name=(folder,'%.1f' %R) atoms = fcc111('Au',size=(2,2,1),a=sqrt(2)*d) L = atoms.get_cell().diagonal() atoms. set_cell(L) angle = L[1]/R atoms.rotate('y',pi/2) atoms.translate( (-atoms[0].x,0,0) ) atoms.translate((R,0,0)) atoms = Atoms(atoms=atoms,container='Wedge') atoms.set_container(angle=angle,height=L[0],physical=False,pbcz=True) calc = Hotbit(SCC=False,txt='%s/optimization_%s.cal' %name,kpts=(nk,1,nk),physical_k=False) atoms.set_calculator(calc) traj = PickleTrajectory( 'md_R%.3f-T%.0f.traj' %(R,T),'w',atoms) dyn = Langevin(atoms,dt*units.fs,units.kB*T,fric) dyn.attach(MDLogger(dyn, atoms, path + 'md_R%.3f-T%.0f.log' %(R,T), header=False, stress=False, peratom=True, mode="w"), interval = 1) dyn.run(mdsteps) cohesion = mean([atoms.get_potential_energy() for a in traj]) /len(atoms) savez('%s/data_%s.npz' %name,cohesion=cohesion) io.write('%s/extended_%s.traj' %name,atoms2)
symbol="Cu", size=(size, size, size), pbc=False) # Describe the interatomic interactions with the Effective Medium Theory atoms.set_calculator(EMT()) # 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. dyn = Langevin(atoms, 5 * 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)
dyn = None if md_style == "Langevin": dyn = Langevin(atoms, timestep, 1.5 * T * units.kB, 0.002) elif md_style == "Verlet": dyn = VelocityVerlet(atoms, timestep) elif md_style == "TESTING": dyn = DynTesting(atoms, timestep=0.1 * units.fs, offset=(0.1, 0., 0.)) energy_file = None def printenergy(a=atoms): epot = a.get_potential_energy() / len(a) ekin = a.get_kinetic_energy() / len(a) energy_file.write("%.5e,%.5e,%.5e,%.5e" % (epot + ekin, epot, ekin, ekin / (1.5 * units.kB)) + "\n") # only enable logging for master node where rank == 0 if rank == 0: energy_file = open("mixer_box_energy.csv", "w+b", buffering=0) energy_file.write("total,potential,kinetic,temperature\n") dyn.attach(printenergy, interval=log_interval) traj = PickleTrajectory(output_file, 'w', atoms) dyn.attach(traj.write, interval=log_interval) printenergy() dyn.run(steps)
# Now let's set the calculator for ``atoms``: atoms.set_calculator(calculator) # Now let's minimize the structure: print("Begin minimizing...") opt = BFGS(atoms) opt.run(fmax=0.001) print() # Now create a callback function that print interesting physical quantities: def printenergy(a=atoms): """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)) # We want to run MD with constant energy using the Langevin algorithm # with a time step of 1 fs, the temperature 300K and the friction # coefficient to 0.02 atomic units. dyn = Langevin(atoms, 1 * units.fs, 300 * units.kB, 0.2) dyn.attach(printenergy, interval=50) # Now run the dynamics: print("Beginning dynamics...") printenergy() dyn.run(500)
T = 1500 # Kelvin # Set up a crystal atoms = FaceCenteredCubic(directions=[[1,0,0],[0,1,0],[0,0,1]], symbol="Cu", size=(size,size,size), pbc=False) # Describe the interatomic interactions with the Effective Medium Theory atoms.set_calculator(EMT()) # 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. dyn = Langevin(atoms, 5*units.fs, T*units.kB, 0.002) #Function to print the potential, kinetic and total energy. def printenergy(a=atoms): #store a reference to atoms in the definition. 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 = PickleTrajectory("moldyn3.traj", 'w', atoms) dyn.attach(traj.write, interval=50) # Now run the dynamics printenergy() dyn.run(5000)
def sphereDynamics(R, T, params): d = params['d'] #2.934 nk = params['nk'] #20 fmax = params['fmax'] #1E-2 fric = params['fric'] #0.002 # equilibration time tau = 10 fs/fric (= mdsteps*dt) dt = params['dt'] #5.0 mdsteps = params['mdsteps'] #int(10/fric/dt) path = params['path'] #'/space/tohekorh/Au_bend/files/' uzsize = params['uz_size'] print 'radius',R name = '%.1f' %R # ATOMS #atoms = fcc111('Au',size=uzsize,a=np.sqrt(2)*d) atoms = get_opmAtomsFlat(T, params) atoms.rotate((0,0,1), -np.pi/6, rotate_cell = True) length1 = np.linalg.norm( atoms.get_cell()[0] ) length2 = np.linalg.norm( atoms.get_cell()[1] ) n1 = ( np.cos(np.pi/3), np.sin(np.pi/3), 0) n2 = (-np.cos(np.pi/3), np.sin(np.pi/3), 0) angle1 = length1/R angle2 = length2/R #view(atoms) # Scale the atoms close to ball Lx = np.linalg.norm(atoms.get_cell()[0] + atoms.get_cell()[1]) Ly = np.linalg.norm(atoms.get_cell()[0] - atoms.get_cell()[1]) phi_max = Ly/R theta_max = Lx/R for a in atoms: r0 = a.position phi = r0[1]/Ly*phi_max theta = r0[0]/Lx*theta_max a.position[0] = R*np.sin(theta) #*np.sin(theta) a.position[1] = R*np.sin(phi) #a.position[1] #R*np.sin(phi) #*np.sin(theta) a.position[2] = R*np.cos(theta) #atoms.translate((0,0,R)) # End scaling atoms = Atoms(atoms=atoms,container='Sphere') atoms.set_container(angle1=angle1,angle2=angle2,n1=n1,n2=n2,mode=4) #view(atoms.extended_copy((2,2,1))) # FOLDERS path_md = path + 'sphere/md_data/T=%.0f/' %T path_opm= path + 'sphere/opm/T=%.0f/' %T checkAndCreateFolder(path_md) checkAndCreateFolder(path_opm) # CALCULATOR calc = Hotbit(SCC=False, kpts=(nk,nk,1),txt= path_opm + 'optimization_%s.cal' %name,) atoms.set_calculator(calc) # RELAX opt = BFGS(atoms, trajectory= path_opm + 'optimization_%s.traj' %name) opt.run(fmax=fmax,steps=1000) #write(path_opm + 'opm_structure_R%.3f' %R, atoms, format='traj') # DYNAMICS traj = PickleTrajectory(path_md + 'md_R%.3f.traj' %R, 'w', atoms) dyn = Langevin(atoms, dt*units.fs, units.kB*T,fric) dyn.attach(MDLogger(dyn, atoms, path_md + 'md_R%.3f.log' %R, header=True, stress=False, peratom=True, mode="w"), interval = 1) dyn.attach(traj.write) dyn.run(mdsteps) traj.close() # load the dynamics back.. To write the extended trajectory traj = PickleTrajectory(path_md + 'md_R%.3f.traj' %R) trajToExtTraj(traj, (2, 2, 1), R, T, angle1, angle2, n1, n2, path)
def cylinderDynamics(R, T, params): nk = params['nk'] #20 fmax = params['fmax'] #1E-2 fric = params['fric'] #0.002 dt = params['dt'] #5.0 mdsteps = params['mdsteps'] #int(10/fric/dt) path = params['path'] #'/space/tohekorh/Au_bend/files/' print 'radius',R, '\n' name = '%.1f' %R # Get the optimal flat atoms , unit-cell config for this temperature: atoms = get_opmAtomsFlat(T, params) # Take the diagonal of the cell: L = atoms.get_cell().diagonal() atoms.set_cell(L) # The wedge angle is: angle = L[1]/R # fiddle with atoms: atoms.rotate('y', np.pi/2) atoms.translate((-atoms[0].x, 0, 0) ) #view(atoms) # Initial map for atoms, to get the on surface of cylinder: phi_max = angle for a in atoms: r0 = a.position phi = r0[1]/L[1]*phi_max a.position[0] = R*np.cos(phi) a.position[1] = R*np.sin(phi) #view(atoms) # proper number of kappa points in angle direction, if angle >= 2*pi/3 the use genuine # physical boundary conditions and proper kappa-points. With 64 atoms in unit cell souhld not # happen as the radius -> very small if angle = 2*pi/3 or larger. # Check that the unit-cell angle is 2*pi/integer. This can be removed! if (2*np.pi/angle)%1 > 0: raise # This does not have any effect unless angle >= 2*pi/3: m = int(round(2*np.pi/angle)) physical = False if m <= 3: nk1 = m physical = True else: nk1 = nk # Set up the wedge container: atoms = Atoms(atoms = atoms, container = 'Wedge') atoms.set_container(angle = angle, height = L[0], physical = physical, pbcz = True) # Check that everything looks good: #view(atoms.extended_copy((2,1,2))) # FOLDERS path_opm = path + 'cylinder/opm/T=%.0f/' %T path_md = path + 'cylinder/md_data/T=%.0f/' %T checkAndCreateFolder(path_opm) checkAndCreateFolder(path_md) # CALCULATOR calc = Hotbit(SCC=False, kpts=(nk1, 1, nk), physical_k = physical, \ txt= path_opm + 'optimization_%s.cal' %name) atoms.set_calculator(calc) # RELAX opt = BFGS(atoms, trajectory= path_opm + 'optimization_%s.traj' %name) opt.run(fmax=fmax, steps=1000) # DYNAMICS traj = PickleTrajectory(path_md + 'md_R%.3f.traj' %R,'w',atoms) # Perform dynamics dyn = Langevin(atoms, dt*units.fs, units.kB*T, fric) dyn.attach(MDLogger(dyn, atoms, path_md + 'md_R%.3f.log' %R, header=True, stress=False, peratom=True, mode="w"), interval = 1) dyn.attach(traj.write) dyn.run(mdsteps) traj.close() # load the dynamics back, to make exteded trajectory: traj = PickleTrajectory(path_md + 'md_R%.3f.traj' %R) trajToExtTraj(traj, (2, 1, 2), R, T, angle, L[0], path)