def __init__(self, pseudos, pseudo_dir="", structure=None, ndtset=1, comment="", decorators=None): """ Args: pseudos: String or list of string with the name of the pseudopotential files. pseudo_dir: Name of the directory where the pseudopotential files are located. structure: file with the structure, :class:`Structure` object or dictionary with ABINIT geo variable ndtset: Number of datasets. comment: Optional string with a comment that will be placed at the beginning of the file. decorators: List of `AbinitInputDecorator` objects. """ # Dataset[0] contains the global variables common to the different datasets # Dataset[1:ndtset+1] stores the variables specific to the different datasets. self._ndtset = ndtset self._datasets = [] for i in range(ndtset + 1): dt0 = None if i > 0: dt0 = self._datasets[0] self._datasets.append(Dataset(index=i, dt0=dt0)) self._datasets[0]["ndtset"] = ndtset # Setup of the pseudopotential files. if isinstance(pseudos, PseudoTable): self._pseudos = pseudos elif all(isinstance(p, Pseudo) for p in pseudos): self._pseudos = PseudoTable(pseudos) else: # String(s) pseudo_dir = os.path.abspath(pseudo_dir) pseudo_paths = [ os.path.join(pseudo_dir, p) for p in list_strings(pseudos) ] missing = [p for p in pseudo_paths if not os.path.exists(p)] if missing: raise self.Error( "Cannot find the following pseudopotential files:\n%s" % str(missing)) self._pseudos = PseudoTable(pseudo_paths) if structure is not None: self.set_structure(structure) if comment is not None: self.set_comment(comment) self._decorators = [] if not decorators else decorators
def __init__(self, structure, pseudos, pseudo_dir="", ndtset=1): """ Args: structure: file with the structure, |Structure| object or dictionary with ABINIT geo variable Accepts also list of objects that can be converted to Structure object. In this case, however, ndtset must be equal to the length of the list. pseudos: String or list of string with the name of the pseudopotential files. pseudo_dir: Name of the directory where the pseudopotential files are located. ndtset: Number of datasets. """ # Setup of the pseudopotential files. if isinstance(pseudos, Pseudo): pseudos = [pseudos] elif isinstance(pseudos, PseudoTable): pseudos = pseudos elif all(isinstance(p, Pseudo) for p in pseudos): pseudos = PseudoTable(pseudos) else: # String(s) pseudo_dir = os.path.abspath(pseudo_dir) pseudo_paths = [ os.path.join(pseudo_dir, p) for p in list_strings(pseudos) ] missing = [p for p in pseudo_paths if not os.path.exists(p)] if missing: raise self.Error( f"Cannot find the following pseudopotential files:\n{str(missing)}" ) pseudos = PseudoTable(pseudo_paths) # Build the list of BasicAbinitInput objects. if ndtset <= 0: raise ValueError(f"ndtset {ndtset} cannot be <=0") if not isinstance(structure, (list, tuple)): self._inputs = [ BasicAbinitInput(structure=structure, pseudos=pseudos) for i in range(ndtset) ] else: assert len(structure) == ndtset self._inputs = [ BasicAbinitInput(structure=s, pseudos=pseudos) for s in structure ]
def __init__(self, structure, spec, option=None): self.structure = structure self.spec = spec if option is not None: option.pop('gap', None) option['nscf_nbands'] = option['nbands'] option.pop('nbands', None) self.option = option print('option:', option) self.bands_fac = 1 self.tests = self.__class__.get_defaults_tests() self.convs = self.__class__.get_defaults_convs() self.response_models = self.__class__.get_response_models() if self.option is None: self.all_converged = False elif len(self.option) == len(self.convs): self.all_converged = True else: self.all_converged = False path_add = '.conv' if self.all_converged else '' self.work_dir = s_name(self.structure) + path_add try: abi_pseudo = os.environ['ABINIT_PS_EXT'] abi_pseudo_dir = os.environ['ABINIT_PS'] except KeyError: abi_pseudo = None abi_pseudo_dir = None pseudos = [] for element in self.structure.composition.element_composition: pseudo = os.path.join(abi_pseudo_dir, str(element) + abi_pseudo) pseudos.append(pseudo) self.pseudo_table = PseudoTable(pseudos)
def test_nc_pseudos(self): """Test norm-conserving pseudopotentials""" for symbol, pseudos in self.nc_pseudos.items(): for pseudo in pseudos: assert repr(pseudo) assert str(pseudo) self.assertTrue(pseudo.isnc) self.assertFalse(pseudo.ispaw) self.assertEqual(pseudo.Z, 14) self.assertEqual(pseudo.symbol, symbol) self.assertEqual(pseudo.Z_val, 4) self.assertGreaterEqual(pseudo.nlcc_radius, 0.0) # Test pickle self.serialize_with_pickle(pseudo, test_eq=False) # Test MSONable self.assertMSONable(pseudo) # HGH pseudos pseudo = self.Si_hgh self.assertFalse(pseudo.has_nlcc) self.assertEqual(pseudo.l_max, 1) self.assertEqual(pseudo.l_local, 0) assert not pseudo.supports_soc assert self.Si_hgh.md5 is not None assert self.Si_hgh == self.Si_hgh # TM pseudos pseudo = self.Si_pspnc self.assertTrue(pseudo.has_nlcc) self.assertEqual(pseudo.l_max, 2) self.assertEqual(pseudo.l_local, 2) assert not pseudo.supports_soc assert self.Si_hgh != self.Si_pspnc # FHI pseudos pseudo = self.Si_fhi self.assertFalse(pseudo.has_nlcc) self.assertEqual(pseudo.l_max, 3) self.assertEqual(pseudo.l_local, 2) assert not pseudo.supports_soc # Test PseudoTable. table = PseudoTable(self.nc_pseudos["Si"]) assert repr(table) assert str(table) self.assertTrue(table.allnc) self.assertTrue(not table.allpaw) self.assertFalse(not table.is_complete) assert len(table) == 3 assert len(table[14]) == 3 assert len(table.select_symbols("Si")) == 3 assert table.zlist == [14] # Test pickle self.serialize_with_pickle(table, test_eq=False)
def get_pseudos(top): """ Find pseudos within top, return :class:`PseudoTable` object sorted by atomic number Z. """ from monty.os.path import find_exts from pymatgen.io.abinit.pseudos import PseudoTable, Pseudo exts = ("psp8",) pseudos = [] for p in find_exts(top, exts, exclude_dirs="_*"): try: pseudos.append(Pseudo.from_file(p)) except Exception as exc: from warnings import warn warn("Exception in pseudo %s:\n%s" % (p.filepath, exc)) return PseudoTable(pseudos).sort_by_z()
def test_methods(self): """Test PseudoTable methods""" table = PseudoTable( ref_files("14si.pspnc", "14si.4.hgh", "14-Si.LDA.fhi")) assert str(table) assert len(table) == 3 for pseudo in table: assert pseudo.isnc assert table.allnc and not table.allpaw assert table.zlist == [14] # Data persistence self.serialize_with_pickle(table, test_eq=False) d = table.as_dict() PseudoTable.from_dict(d) self.assertMSONable(table) selected = table.select_symbols("Si") assert len(selected) == len( table) and selected.__class__ is table.__class__ with self.assertRaises(ValueError): table.pseudos_with_symbols("Si")
def pseudos(*filenames): """Returns a PseudoTable constructed from the input filenames located in tests/data/pseudos.""" pseudos = list(map(pseudo, filenames)) return PseudoTable(pseudos)
def scf_ph_inputs(structure, options): """ This function constructs the input files for the phonon calculation: GS input + the input files for the phonon calculation. """ abi_pseudo = os.environ['ABINIT_PS_EXT'] abi_pseudo_dir = os.environ['ABINIT_PS'] pseudos = [] for element in structure.composition.element_composition: pseudo = os.path.join(abi_pseudo_dir, str(element) + abi_pseudo) pseudos.append(pseudo) pseudos = PseudoTable(pseudos) #print('bounds:\n', structure.calc_kptbounds) #print('ngkpt:\n', structure.calc_ngkpt(4)) print('ks:\n', structure.calc_ksampling(4)) # try to get the qpoints from this ... qptbounds = structure.calc_kptbounds() qptbounds = np.reshape(qptbounds, (-1, 3)) # List of q-points for the phonon calculation. qpoints = [ 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 2.50000000E-01, 0.00000000E+00, 0.00000000E+00, 2.50000000E-01, 0.00000000E+00, 2.50000000E+00, 5.00000000E-01, 0.00000000E+00, 0.00000000E+00, 2.50000000E-01, 2.50000000E-01, 0.00000000E+00, 5.00000000E-01, 2.50000000E-01, 0.00000000E+00, -2.50000000E-01, 2.50000000E-01, 0.00000000E+00, 5.00000000E-01, 5.00000000E-01, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 2.50000000E-01, -2.50000000E-01, 5.00000000E-01, 2.50000000E-01, ] qpoints2 = [ 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 5.00000000E-01, 0.00000000E+00, 0.00000000E+00, 0.00000000E-01, 5.00000000E-01, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 5.00000000E-01, 5.00000000E-01, 5.00000000E-01, 0.00000000E+00, 0.00000000E+00, 5.00000000E-01, 5.00000000E-01, 5.00000000E-01, 0.00000000E+00, 5.00000000E-01, 5.00000000E-01, 5.00000000E-01, 5.00000000E-01, ] qpoints = np.reshape(qpoints, (-1, 3)) qpoints = unique_rows(np.concatenate((qpoints, qptbounds), axis=0)) if os.path.isfile('qpoints'): f = open('qpoints', 'r') qpoints = np.reshape(ast.literal_eval(f.read()), (-1, 3)) f.close() # Global variables used both for the GS and the DFPT run. global_vars = dict(istwfk='*1', ecut=16.0, ngkpt=[8, 8, 8], shiftk=[0, 0, 0], paral_kgb=0, nstep=200) global_vars.update(options) to_vecs(global_vars) inp = abilab.AbiInput(pseudos=pseudos, ndtset=1 + len(qpoints)) inp.set_structure(structure) inp.set_variables(**global_vars) inp[1].set_variables(tolwfr=1.0e-18, prtden=1, paral_kgb=1) for i, qpt in enumerate(qpoints): # Response-function calculation for phonons. inp[i + 2].set_variables( tolvrs=1.0e-10, kptopt=3, iscf=5, rfphon=1, # Will consider phonon-type perturbation nqpt=1, # One wavevector is to be considered qpt=qpt, # This wavevector is q=0 (Gamma) ) #rfatpol 1 1 # Only the first atom is displaced #rfdir 1 0 0 # Along the first reduced coordinate axis #kptopt 2 # Automatic generation of k points, taking # Split input into gs_inp and ph_inputs return inp.split_datasets()