def setup(self): """ Setup initial relaxation run Uses the following files from the most local .../settings/calctype.name directory: INCAR: VASP input settings KPOINTS: VASP kpoints settings POSCAR: reference for KPOINTS if KPOINTS mode is not A/AUTO/Automatic SPECIES: info for each species such as which POTCAR files to use, MAGMOM, GGA+U, etc. Uses the following files from the .../config directory: POS: structure of the configuration to be relaxed """ incarfile = casm.settings_path("INCAR",self.casm_settings["curr_calctype"],self.configdir) prim_kpointsfile = casm.settings_path("KPOINTS",self.casm_settings["curr_calctype"],self.configdir) prim_poscarfile = casm.settings_path("POSCAR",self.casm_settings["curr_calctype"],self.configdir) super_poscarfile = os.path.join(self.configdir,"POS") speciesfile = casm.settings_path("SPECIES",self.casm_settings["curr_calctype"],self.configdir) if incarfile == None or not os.path.isfile(incarfile): raise vasp.VaspError("Relax.setup failed. No incar file: '" + incarfile + "'") if prim_kpointsfile == None or not os.path.isfile(prim_kpointsfile): raise vasp.VaspError("Relax.setup failed. No kpoints file: '" + prim_kpointsfile + "'") if prim_poscarfile == None or not os.path.isfile(prim_poscarfile): # raise vasp.VaspError("Relax.setup failed. No prim poscar file: '" + prim_poscarfile + "'") warnings.warn("No prim poscar file: '" + prim_poscarfile + "', I hope your KPOINTS mode is A/AUTO/Automatic \ or this will fail!!!", vasp.VaspWarning) prim_poscarfile = None if super_poscarfile == None or not os.path.isfile(super_poscarfile): raise vasp.VaspError("Relax.setup failed. No pos file: '" + super_poscarfile + "'") if speciesfile == None or not os.path.isfile(speciesfile): raise vasp.VaspError("Relax.setup failed. No species file: '" + speciesfile + "'") sys.stdout.flush() vasp.io.write_vasp_input(self.calcdir, incarfile, prim_kpointsfile, prim_poscarfile, super_poscarfile, speciesfile, self.sort)
def setup(self): """ Setup initial relaxation run Uses the following files from the most local .../settings/calctype.name directory: INCAR: VASP input settings KPOINTS: VASP kpoints settings POSCAR: reference for KPOINTS if KPOINTS mode is not A/AUTO/Automatic SPECIES: info for each species such as which POTCAR files to use, MAGMOM, GGA+U, etc. Uses the following files from the .../config directory: POS: structure of the configuration to be relaxed """ incarfile = casm.settings_path("INCAR", self.casm_settings["curr_calctype"], self.configdir) prim_kpointsfile = casm.settings_path( "KPOINTS", self.casm_settings["curr_calctype"], self.configdir) prim_poscarfile = casm.settings_path( "POSCAR", self.casm_settings["curr_calctype"], self.configdir) super_poscarfile = os.path.join(self.configdir, "POS") speciesfile = casm.settings_path("SPECIES", self.casm_settings["curr_calctype"], self.configdir) if incarfile == None or not os.path.isfile(incarfile): raise vasp.VaspError("Relax.setup failed. No incar file: '" + incarfile + "'") if prim_kpointsfile == None or not os.path.isfile(prim_kpointsfile): raise vasp.VaspError("Relax.setup failed. No kpoints file: '" + prim_kpointsfile + "'") if prim_poscarfile == None or not os.path.isfile(prim_poscarfile): # raise vasp.VaspError("Relax.setup failed. No prim poscar file: '" + prim_poscarfile + "'") warnings.warn( "No prim poscar file: '" + prim_poscarfile + "', I hope your KPOINTS mode is A/AUTO/Automatic \ or this will fail!!!", vasp.VaspWarning) prim_poscarfile = None if super_poscarfile == None or not os.path.isfile(super_poscarfile): raise vasp.VaspError("Relax.setup failed. No pos file: '" + super_poscarfile + "'") if speciesfile == None or not os.path.isfile(speciesfile): raise vasp.VaspError("Relax.setup failed. No species file: '" + speciesfile + "'") sys.stdout.flush() vasp.io.write_vasp_input(self.calcdir, incarfile, prim_kpointsfile, prim_poscarfile, super_poscarfile, speciesfile, self.sort)
def report(self): """Report final results to properties.calc.json file in configuration directory.""" outputfile = os.path.join(self.calcdir, "properties.calc.json") if os.path.isfile(outputfile): with open(outputfile, 'r') as file: output = json.load(file) else: output = dict() vrun = vasp.io.Vasprun( os.path.join(self.calcdir, "run.final", "vasprun.xml") ) # the calculation is run on the 'sorted' POSCAR, need to report results 'unsorted' if self.sort: super_poscarfile = os.path.join(self.configdir,"POS") speciesfile = casm.settings_path("SPECIES",self.casm_settings["curr_calctype"],self.configdir) species_settings = vasp.io.species_settings(speciesfile) super = vasp.io.Poscar(super_poscarfile, species_settings) unsort_dict = super.unsort_dict() else: # fake unsort_dict (unsort_dict[i] == i) unsort_dict = dict(zip(range(0,len(vrun.basis)),range(0,len(vrun.basis)))) print unsort_dict # unsort_dict: # Returns 'unsort_dict', for which: unsorted_dict[orig_index] == sorted_index; # unsorted_dict[sorted_index] == orig_index # For example: # 'unsort_dict[0]' returns the index into the unsorted POSCAR of the first atom in the sorted POSCAR results = dict() results["is_complete"] = vrun.is_complete results["atom_type"] = super.type_atoms results["atoms_per_type"] = super.num_atoms results["coord_mode"] = vrun.coord_mode # as lists results["relaxed_forces"] = [ None for i in range(len(vrun.forces))] for i, v in enumerate(vrun.forces): results["relaxed_forces"][unsort_dict[i] ] = vrun.forces[i] results["relaxed_lattice"] = vrun.lattice results["relaxed_basis"] = [ None for i in range(len(vrun.basis))] for i, v in enumerate(vrun.basis): results["relaxed_basis"][unsort_dict[i] ] = vrun.basis[i] results["relaxed_energy"] = vrun.total_energy with open(outputfile, 'w') as file: json.dump(results, file, indent=4, sort_keys=True) print "Wrote " + outputfile sys.stdout.flush()
def report(self): """Report final results to properties.calc.json file in configuration directory.""" outputfile = os.path.join(self.calcdir, "properties.calc.json") if os.path.isfile(outputfile): with open(outputfile, 'r') as file: output = json.load(file) else: output = dict() vrun = vasp.io.Vasprun( os.path.join(self.calcdir, "run.final", "vasprun.xml") ) # the calculation is run on the 'sorted' POSCAR, need to report results 'unsorted' if self.sort: super_poscarfile = os.path.join(self.configdir,"POS") speciesfile = casm.settings_path("SPECIES",self.casm_settings["curr_calctype"],self.configdir) species_settings = vasp.io.species_settings(speciesfile) super = vasp.io.Poscar(super_poscarfile, species_settings) unsort_dict = super.unsort_dict() else: # fake unsort_dict (unsort_dict[i] == i) unsort_dict = dict(zip(range(0,len(vrun.basis)),range(0,len(vrun.basis)))) print unsort_dict # unsort_dict: # Returns 'unsort_dict', for which: unsorted_dict[orig_index] == sorted_index; # unsorted_dict[sorted_index] == orig_index # For example: # 'unsort_dict[0]' returns the index into the unsorted POSCAR of the first atom in the sorted POSCAR results = dict() results["is_complete"] = vrun.is_complete results["atom_type"] = super.type_atoms results["atoms_per_type"] = super.num_atoms results["coord_mode"] = vrun.coord_mode # as lists results["relaxed_forces"] = [ None for i in range(len(vrun.forces))] for i, v in enumerate(vrun.forces): results["relaxed_forces"][unsort_dict[i] ] = casm.NoIndent(vrun.forces[i]) results["relaxed_lattice"] = [casm.NoIndent(v) for v in vrun.lattice] results["relaxed_basis"] = [ None for i in range(len(vrun.basis))] for i, v in enumerate(vrun.basis): results["relaxed_basis"][unsort_dict[i] ] = casm.NoIndent(vrun.basis[i]) results["relaxed_energy"] = vrun.total_energy with open(outputfile, 'w') as file: file.write(json.dumps(results, file, cls=casm.NoIndentEncoder, indent=4, sort_keys=True)) print "Wrote " + outputfile sys.stdout.flush()
def __init__(self, configdir = None, convtype = None, auto = True, sort = True): """ Construct a VASP convergence job object. Args: configdir: path to configuration convtype: type of convergence (e.g. 'kpoints' or 'encut') auto: True if using pbs module's JobDB to manage pbs jobs """ if configdir == None: configdir = os.getcwd() print "Reading CASM settings" self.casm_settings = casm.casm_settings(configdir) if self.casm_settings == None: raise vaspwrapper.VaspWrapperError("Not in a CASM project. The file '.casm/project_settings.json' was not found.") print "Constructing a CASM VASPWrapper Converge object" sys.stdout.flush() print " Setting up directories" sys.stdout.flush() # store path to .../config, if not existing raise self.configdir = os.path.abspath(configdir) if not os.path.isdir(self.configdir): raise vasp.VaspError("Error in casm.vasp.relax: Did not find directory: " + self.configdir) sys.stdout.flush() # store path to .../config/calctype.name, and create if not existing self.calcdir = os.path.join(self.configdir, self.casm_settings["curr_calctype"]) try: os.mkdir(self.calcdir) except: pass # read the settings json file print " Reading converge.json settings file" sys.stdout.flush() setfile = casm.settings_path("converge.json",self.casm_settings["curr_calctype"],self.configdir) if setfile == None: raise vaspwrapper.VaspWrapperError("Could not find .../settings/" + self.casm_settings["curr_calctype"] + "/converge.json file.") sys.stdout.flush() self.settings = vaspwrapper.read_settings(setfile) # add required keys to settings if not present if not "ncore" in self.settings: self.settings["ncore"] = None if not "npar" in self.settings: self.settings["npar"] = None if not "kpar" in self.settings: self.settings["kpar"] = None if not "vasp_cmd" in self.settings: self.settings["vasp_cmd"] = None if not "ncpus" in self.settings: self.settings["ncpus"] = None if not "encut" in self.settings: self.settings["encut"] = None if not "kpoints" in self.settings: self.settings["kpoints"] = None if not "nrg_convergence" in self.settings: self.settings["nrg_convergence"] = None if not "run_limit" in self.settings: self.settings["run_limit"] = None self.auto = auto self.sort = sort print "VASP Converge object constructed\n" sys.stdout.flush()
def __init__(self, configdir=None, auto = True, sort = True): """ Construct a VASP relaxation job object. Args: configdir: path to configuration auto: True if using pbs module's JobDB to manage pbs jobs """ if configdir == None: configdir = os.getcwd() print "Reading CASM settings" self.casm_settings = casm.casm_settings(configdir) if self.casm_settings == None: raise vaspwrapper.VaspWrapperError("Not in a CASM project. The file '.casm' directory was not found.") print "Constructing a CASM VASPWrapper Relax object" sys.stdout.flush() print " Setting up directories" sys.stdout.flush() # store path to .../config, if not existing raise self.configdir = os.path.abspath(configdir) if not os.path.isdir(self.configdir): raise vasp.VaspError("Error in casm.vasp.relax: Did not find directory: " + self.configdir) sys.stdout.flush() # store path to .../config/calctype.name, and create if not existing self.calcdir = os.path.join(self.configdir, self.casm_settings["curr_calctype"]) try: os.mkdir(self.calcdir) except: pass # read the settings json file print " Reading relax.json settings file" sys.stdout.flush() setfile = casm.settings_path("relax.json",self.casm_settings["curr_calctype"],self.configdir) if setfile == None: raise vaspwrapper.VaspWrapperError("Could not find .../settings/" + self.casm_settings["curr_calctype"] + "/relax.json file.") sys.stdout.flush() self.settings = vaspwrapper.read_settings(setfile) # add required keys to settings if not present if not "ncore" in self.settings: self.settings["ncore"] = None if not "npar" in self.settings: self.settings["npar"] = None if not "kpar" in self.settings: self.settings["kpar"] = None if not "vasp_cmd" in self.settings: self.settings["vasp_cmd"] = None if not "ncpus" in self.settings: self.settings["ncpus"] = None if not "run_limit" in self.settings: self.settings["run_limit"] = None self.auto = auto self.sort = sort print "VASP Relax object constructed\n" sys.stdout.flush()