def submit(self, prototype, ncpus=None, batch_no=None, calc_parameters=None, **kwargs): """Submit a calculation for a prototype, generating atoms with build_bulk and enumerator""" cell_parameters = prototype.get('parameters', None) BB = BuildBulk(prototype['spacegroup'], prototype['wyckoffs'], prototype['species'], ) atoms = BB.get_atoms(cell_parameters=cell_parameters) p_name = BB.get_prototype_name(prototype['species']) formula = atoms.get_chemical_formula() Sub = self.Submitter(atoms=atoms, ncpus=ncpus, calc_parameters=calc_parameters) Sub.submit_calculation() key_value_pairs = {'p_name': p_name, 'path': Sub.excpath, 'spacegroup': BB.spacegroup, 'wyckoffs': json.dumps(BB.wyckoffs), 'species': json.dumps(BB.species), 'ncpus': Sub.ncpus} key_value_pairs.update(kwargs) if batch_no: key_value_pairs.update({'batch': batch_no}) self.write_submission(key_value_pairs)
def test6_all_spacegroups(self): images = [] spacegroups = range(195, 230) spacegroups, spacegroup_letters = get_wyckoff_letters(spacegroups) for sg in spacegroups: wyckoffs = spacegroup_letters[sg - 1][::-1][:5] species = metals[:len(wyckoffs)] print('----------', sg, '------------') BB = BuildBulk(sg, wyckoffs, species) atoms = BB.get_atoms(primitive_cell=False) PC = PrototypeClassification(atoms) prototype = PC.get_classification(include_parameters=False) if not prototype['spacegroup'] == sg: print(' change in spacegroup', sg, '----->', prototype['spacegroup']) print(' ', prototype['p_name']) else: assert prototype['wyckoffs'] == wyckoffs, \ '{} --->> {}'.format(prototype['wyckoffs'], wyckoffs)
def test_write_model_nersc(self): bb_iron = BuildBulk(225, ['a', 'c'], ['Mn', 'O']) atoms = bb_iron.get_atoms() submitter = NerscSubmit(atoms, account='projectname', basepath='.') submitter.set_execution_path(strict_format=False) submitter.write_submission_files() submitter.write_submit_script()
def test2_set_parameters(self): BB = BuildBulk(225, ['a'], ["Cu"]) atoms = BB.get_atoms(cell_parameters={'a': 5}) unit_cell_lengths = np.linalg.norm(atoms.cell, axis=1) assert np.all(np.isclose(unit_cell_lengths, 5 / np.sqrt(2))) atoms = BB.get_atoms(cell_parameters={'a': 5}, primitive_cell=False) unit_cell_lengths = np.linalg.norm(atoms.cell, axis=1) assert np.all(np.isclose(unit_cell_lengths, 5))
def setUp(self): self.bb_iron = BuildBulk(225, ['a', 'c'], ['Mn', 'O']) atoms = self.bb_iron.get_atoms() self.submitter = TriSubmit(atoms, basepath_ext='tests', calc_parameters={'encut': 300, 'kspacing': 0.5}, ncpus=1, queue='small' ) self.pwd = os.getcwd() self.tempdir = tempfile.mkdtemp() os.chdir(self.tempdir)
class TriSubmitTest(unittest.TestCase): def setUp(self): self.bb_iron = BuildBulk(225, ['a', 'c'], ['Mn', 'O']) atoms = self.bb_iron.get_atoms() self.submitter = TriSubmit(atoms, basepath_ext='tests', calc_parameters={'encut': 300, 'kspacing': 0.5}, ncpus=1, queue='small' ) self.pwd = os.getcwd() self.tempdir = tempfile.mkdtemp() os.chdir(self.tempdir) def tearDown(self): os.chdir(self.pwd) shutil.rmtree(self.tempdir) def test_write_poscar(self): self.submitter.write_poscar('.') def test_write_model(self): self.submitter.write_model('.') with open('model.py') as f: model_text = f.readlines() def test_submit(self): self.submitter.submit_calculation()
# Allow lattice constants to be optimized for del_param in ['a', 'b', 'c']: if del_param in cell_parameters: del cell_parameters[del_param] spacegroup = int(row[4]) wyckoffs = eval(row[6]) species = eval(row[5]) atomA = species[0] # Change to TiO2 structure for i in range(len(species)): if species[i] == atomA: species[i] = 'Ti' else: species[i] = 'O' try: bulk_generator = BuildBulk(spacegroup=int(row[4]), wyckoffs=eval(row[6]), species=species, cell_parameters=cell_parameters) atoms = bulk_generator.atoms if atoms: view(atoms) database.write(atoms) except BaseException: print('Error: something is wrong with this structure') continue
def test_write_model(self): bb_iron = BuildBulk(225, ['a', 'c'], ['Mn', 'O']) atoms = bb_iron.get_atoms() self.submitter = TriSubmit(atoms, basepath_ext='tests') self.submitter.write_model('.')
def store_atoms_for_prototype(self, prototype, max_candidates=1): p_name = prototype['name'] counts = [] for a in p_name.split('_')[0]: if a.isdigit(): counts[-1] += int(a) - 1 else: counts += [1] species_lists = self.get_species_lists( prototype['species'], prototype['permutations'], counts) cell_parameters = prototype.get('cell_parameters', None) if cell_parameters: cell_parameters = json.load(cell_parameters) for species in species_lists: structure_name = str(prototype['spacegroup']) for spec, wy_spec in zip(species, prototype['wyckoffs']): structure_name += '_{}_{}'.format(spec, wy_spec) with PrototypeSQL(filename=self.filename) as DB: if DB.ase_db.count(structure_name=structure_name) > 0: continue for row in DB.ase_db.select(p_name=prototype['name'], limit=1): cell_parameters = json.loads(row.cell_parameters) BB = BuildBulk(prototype['spacegroup'], prototype['wyckoffs'], species, ) atoms_list, parameters = \ BB.get_wyckoff_candidate_atoms(proximity=1, primitive_cell=True, return_parameters=True, max_candidates=max_candidates) key_value_pairs = {'p_name': prototype['name'], 'spacegroup': prototype['spacegroup'], 'wyckoffs': json.dumps(prototype['wyckoffs']), 'species': json.dumps(species), 'structure_name': structure_name, 'source': 'prototype', 'relaxed': 0, 'completed': 0, 'submitted': 0} for i, atoms in enumerate(atoms_list): atoms.info.pop('spacegroup') if 'spacegroup_kinds' in atoms.info: atoms.info.pop('spacegroup_kinds') key_value_pairs.update(atoms.info) key_value_pairs.update( {'cell_parameters': json.dumps(parameters[i])}) fitness = get_fitness(atoms) apf = get_covalent_density(atoms) key_value_pairs.update({'fitness': fitness, 'apf': apf}) with PrototypeSQL(filename=self.filename) as DB: DB.ase_db.write(atoms, key_value_pairs)
def test1_no_parameters(self): BB = BuildBulk(225, ['a'], ["Cu"]) atoms = BB.get_atoms(proximity=1) unit_cell_lengths = np.linalg.norm(atoms.cell, axis=1) assert np.all(np.isclose(unit_cell_lengths, 2.629, rtol=0.01))
from protosearch.build_bulk.build_bulk import BuildBulk from ase.visualize import view BB = BuildBulk(47, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'], ['Cu', 'Pd', 'Pt','Au', 'Cu', 'Pd', 'Pt','Au']) atoms = BB.get_atoms(proximity=1) view(atoms)