def writeNEB( self, runfile, neb, kpts, ): dictionary = self.__ase_calculator.parameters.copy() dictionary.pop('pseudo_qualifier') dictionary.pop('pseudo_path') dictionary.pop('ignore_bad_restart_file') dictionary.pop('label') dictionary.pop('atoms') dictionary['kpts'] = kpts c_string = 'calculator = ' c_string += makeScript('Siesta', dictionary, detail_level=ALL) + '\n' path = os.path.dirname(runfile) n_images = len(neb.images) filename = join(path, 'neb.traj') write_traj(filename, neb.images) script = """from CalcTroll.Programs.ASE.Trajectory import myread_traj, write_traj, Trajectory from ase import io from ase.neb import NEB from ase.optimize import FIRE from CalcTroll.Programs.ASESIESTA import SiestaCalculator as Siesta """ script += """calculator = %s""" % c_string + """ kwargs = calculator.parameters.copy() images = [] for i in range(%d):""" % n_images + """ kwargs['label'] = 'siesta_%d' % i calculator = Siesta(**kwargs) image = myread_traj('neb.traj', i) image.set_calculator(calculator) image.get_total_energy() images.append(image) """ + """ k=0.5 neb = NEB(images, k=k, climb=False) qn = FIRE(neb, trajectory='neb.traj') qn.run(fmax=%.3f) """ % self['force_tolerance'] with open(runfile, 'w') as f: f.write(script)
def calculatorScript( self, atoms, kpts, min_iterations=True, save_behaviour=None, ): net_charge = 0 for doping in atoms.dopings(): net_charge += doping.charge() c_string = 'calculator = ' dictionary = self.__ase_calculator.parameters.copy() dictionary['fdf_arguments']['NetCharge'] = net_charge dictionary.pop('pseudo_qualifier') dictionary.pop('pseudo_path') dictionary.pop('ignore_bad_restart_file') dictionary.pop('label') dictionary.pop('atoms') if not min_iterations: dictionary['fdf_arguments']['MinSCFIterations'] = 1 dictionary['kpts'] = kpts c_string += makeScript('Siesta', dictionary, detail_level=API.ALL) + '\n' return c_string
def writeRelaxation(self, runfile, atoms, kpts, relax_cell, save_behaviour, ): atoms = atoms.copy() net_charge = 0 for doping in atoms.dopings(): net_charge += doping.charge() # Remove electrodes to avoid transiesta relacation (for now). atoms.purgeTags() c_string = 'calculator = ' dictionary = self.__ase_calculator.parameters.copy() dictionary['fdf_arguments']['NetCharge'] = net_charge dictionary.pop('pseudo_qualifier') dictionary.pop('pseudo_path') dictionary.pop('ignore_bad_restart_file') dictionary.pop('label') dictionary.pop('atoms') dictionary['kpts'] = kpts c_string += makeScript('Siesta', dictionary, detail_level=API.ALL) + '\n' path = os.path.dirname(runfile) filename = join(path, 'input.traj') if relax_cell: eff_force_tolerance = np.min([self['force_tolerance'], self['stress_tolerance']]) else: eff_force_tolerance = self['force_tolerance'] write_traj(filename, atoms) script = """from CalcTrollASE.Trajectory import myread_traj, write_traj, Trajectory from ase.constraints import UnitCellFilter from ase.optimize import FIRE, BFGS from CalcTroll.Plugins.Programs.Siesta.Siesta import SiestaCalculator as Siesta from ase.calculators.siesta.parameters import Specie from CalcTroll.Plugins.Programs.Siesta.SiestaIO import convertXVtoASE """ script += c_string script += """ atoms = myread_traj('input.traj', -1) try: restart_atoms = myread_traj('relax.traj', -1) except: print 'initializing from input.traj...' else: print 'restarting from previous geometry...' atoms.positions = restart_atoms.positions atoms.cell = restart_atoms.cell atoms.set_calculator(calculator) """ if relax_cell: pbc = tuple(atoms.get_pbc()) if pbc == (False, False, True): mask = (False, False, True, False, False, False) elif pbc == (True, True, True): mask = None script += """ relax = UnitCellFilter(atoms, mask=%s) """ % str(mask) else: script += "relax = atoms\n" script += """ opt = BFGS(relax) traj = Trajectory('relax.traj', 'w', atoms) opt.attach(traj) opt.run(fmax=%.5f) """%eff_force_tolerance with open(runfile, 'w') as f: f.write(script)