def test_read(): from aiida_crystal_dft.io.f34 import Fort34 from aiida_crystal_dft.tests import TEST_DIR file_name = os.path.join(TEST_DIR, 'input_files', 'mgo_sto3g_external.crystal.gui') reader = Fort34().read(file_name) assert reader.centring == 5 assert reader.n_symops == 48 assert reader.space_group == 225 file_name = os.path.join(TEST_DIR, 'output_files', 'mgo_sto3g', 'fort.34') reader = Fort34().read(file_name) assert reader.centring == 5 assert reader.n_symops == 48 assert reader.space_group == 225
def test_from_to_ase(aiida_profile, test_ase_structure): import numpy as np from aiida_crystal_dft.io.f34 import Fort34 reader = Fort34().from_ase(test_ase_structure) result_struct = reader.to_ase() assert (np.all(test_ase_structure.get_cell() == result_struct.get_cell())) assert (len(test_ase_structure) == len(result_struct))
def test_from_ase(aiida_profile, test_ase_structure): from aiida_crystal_dft.io.f34 import Fort34 reader = Fort34().from_ase(test_ase_structure) assert reader.space_group == 225 assert reader.crystal_type == 6 assert reader.centring == 5 assert reader.abc[0, 0] == 4.21 assert len(reader.positions) == 8 assert reader.atomic_numbers[0] == 12
def _prepare_input_files(self, folder): basis_dict = self._validate_basis_input(dict(self.inputs)) params = self.inputs.parameters.get_dict() # check if both SPINLOCK and is_magnetic are present; in this case SPINLOCK takes precedence if 'spinlock' in params['scf'] and self.inputs.is_magnetic: self.logger.warning( 'Both SPINLOCK and is_magnetic are present, dropping is_magnetic' ) self.inputs.is_magnetic = False # create input files: d12, taking into account try: basis_dict['basis_family'].set_structure(self.inputs.structure) if "use_oxistates" in self.inputs: basis_dict['basis_family'].set_oxistates( self.inputs.use_oxistates.get_dict()) self.out('oxidation_states', Dict(dict=self.inputs.use_oxistates.get_dict())) elif self.inputs.guess_oxistates: oxi_states = guess_oxistates(self.inputs.structure) basis_dict['basis_family'].set_oxistates(oxi_states) # save oxidation states for future reference self.out('oxidation_states', Dict(dict=oxi_states)) if self.inputs.is_magnetic: try: spinlock = guess_spinlock(self.inputs.structure) params['scf']['spinlock'] = {} params['scf']['spinlock']['SPINLOCK'] = [ spinlock, int(self.inputs.spinlock_steps) ] # adding SPIN keywords if they're not present if 'single' in params['scf']: params['scf']['single'] = 'UHF' elif 'dft' in params['scf']: params['scf']['dft']['SPIN'] = True except NotImplementedError: self.logger.info( "is_magnetic is True for non-magnetic structure") d12_file = D12(parameters=self.inputs.parameters.get_dict(), basis=basis_dict['basis_family']) except (AttributeError, ValueError, NotImplementedError) as err: raise InputValidationError( "an input file could not be created from the parameters: {}". format(err)) with open( folder.get_abs_path( self.inputs.metadata.options.input_filename), 'w') as f: f.write(str(d12_file)) # create input files: fort.34 with open(folder.get_abs_path(self._GEOMETRY_FILE_NAME), 'w') as f: Fort34(basis=basis_dict['basis_family']).from_aiida( self.inputs.structure).write(f)
from aiida_crystal_dft.io.d3 import D3 from aiida_crystal_dft.io.f25 import Fort25 from aiida_crystal_dft.io.f34 import Fort34 from aiida_crystal_dft.utils.kpoints import construct_kpoints_path, get_explicit_kpoints_path, get_shrink_kpoints_path import psutil EXEC_PATH = "/usr/bin/Pproperties" #EXEC_PATH = "/root/bin/properties" EXEC_TIMEOUT = 300 # NB five minutes exec_cmd = "/usr/bin/mpirun -np 1 --allow-run-as-root -wd %s %s > %s 2>&1" #exec_cmd = "cd %s && %s < INPUT > %s 2>&1" config = ConfigParser() config.read(CONFIG_FILE) f34_input = Fort34() def is_conductor(band_stripes): for s in band_stripes: top, bottom = max(s), min(s) if bottom < 0 and top > 0: return True elif bottom > 0: break return False def get_band_gap_info(band_stripes): """ Args: band_stripes: (2d-array) spaghetti in eV Returns:
elem_pair, more_query_args=dict(lattices='cubic')) structures_by_sgn = {} for s in structures: structures_by_sgn.setdefault(s.info['spacegroup'].no, []).append(s) for sgn_cls in structures_by_sgn: if how_many and counter >= how_many: raise SystemExit # get structures with the minimal number of atoms and find one with the median cell vectors minimal_struct = min([len(s) for s in structures_by_sgn[sgn_cls]]) cells = np.array([ s.get_cell().reshape(9) for s in structures_by_sgn[sgn_cls] if len(s) == minimal_struct ]) median_cell = np.median(cells, axis=0) median_idx = int( np.argmin(np.sum((cells - median_cell)**2, axis=1)**0.5)) target_obj = structures_by_sgn[sgn_cls][median_idx] f34_input = Fort34([bs_repo[el] for el in elem_pair]) struct_input = f34_input.from_ase(target_obj) struct_input = str(struct_input) setup_input = get_input(calc_setup['parameters']['crystal'], elem_pair, bs_repo, target_obj.info['phase']) yac.queue_submit_task(target_obj.info['phase'], dict(structure=struct_input, input=setup_input)) counter += 1
def parse_out_structure(self, f): if not self.converged_ionic: return None parser = Fort34().read(f) return parser.to_aiida()
try: symprec = float(sys.argv[2]) except: symprec = 3E-02 # NB needs tuning print('symprec = %s' % symprec) label = sys.argv[1].split(os.sep)[-1].split('.')[0] + \ " " + spglib.get_spacegroup(ase_obj, symprec=symprec) ase_obj, error = refine(ase_obj, accuracy=symprec, conventional_cell=True) assert not error, error yaconfig = ConfigParser() yaconfig.read(CONFIG_FILE) yac = Yascheduler(yaconfig) calc_setup = get_template() bs_repo = get_basis_sets(calc_setup['basis_family']) #bs_repo_tzvp = get_basis_sets('./tzvp_RE') #bs_repo_other = get_basis_sets('./hand_made_bs') #bs_repo = {**bs_repo_tzvp , **bs_repo_other} elements = list(set(ase_obj.get_chemical_symbols())) f34_input = Fort34([bs_repo[el] for el in elements]) struct_input = str(f34_input.from_ase(ase_obj)) setup_input = get_input(calc_setup['parameters']['crystal'], elements, bs_repo, label) result = yac.queue_submit_task(label, dict(structure=struct_input, input=setup_input)) print(label) print(result)