K.nspecies < 7) n = len(results) # number of avaiable data points X_sp_metals = [] Y_sp_metals = [] materials_info = [] for i, result in enumerate(results): try: if result.catalog == 'ICSD\n': URL = result.files['DOSCAR.static.xz'] save_xz(result.compound + '.xz', URL) # Construct RDF with POSCAR crystal = Structure.from_str(result.files['CONTCAR.relax.vasp'](), fmt='poscar') # Get elements in the compound elements = result.species last_element = elements[-1] last_element = last_element[:-1] elements[-1] = last_element # Collecting for sp_metals compound j = 0 for element in elements: if element in sp_system: j += 1 if j == len(elements): X_sp_metals.append(RDF(crystal).RDF[1, :]) dos = get_DOS_fermi(result.compound + '.txt', result)
def test_check_points_3(): settings = { 'deformation_fraction': [-0.05, 0.05], 'num_deformations': 3, 'deformation_scheme': 'volume', 'run_isif': 4, 'phonon': True, 'phonon_supercell_matrix': [[-2, 2, 2], [2, -2, 2], [2, 2, -2]], 'override_default_vasp_params': { 'user_incar_settings': { 'EDIFF_PER_ATOM': 1e-07, 'Relax_settings': { 'PREC': 'HIGH', 'grid_density': 1000 }, 'Static_settings': { 'PREC': 'HIGH', 'grid_density': 1000 } }, 'user_kpoints_settings': { 'grid_density': 1000 } }, 'metadata': { 'tag': '67783198-6d5a-40c2-8d49-4f03e50ac130' } } ################ PARAMETERS FOR WF ############################# #str, the absolute path of db.json file, e.g. /storage/home/mjl6505/atomate/config/db.json # If None, it will use the configuration in fireworks #db_file = settings.get('db_file', DB_FILE) db_file = loadfn(config_to_dict()["FWORKER_LOC"])["env"]["db_file"] #str, the vasp command, if None then find in the FWorker configuration vasp_cmd = settings.get('vasp_cmd', VASP_CMD) #dict, metadata to be included, this parameter is useful for filter the data, e.g. metadata={"phase": "BCC_A2", "tag": "AFM"} metadata = settings.get('metadata', {}) tag = metadata.get('tag', '{}'.format(str(uuid4()))) metadata.update({'tag': tag}) #list/tuple(min, max) or float(-max, max), the maximum amplitude of deformation, e.g. (-0.15, 0.15) means (0.95, 1.1) in volume deformation_fraction = settings.get('deformation_fraction', (-0.15, 0.20)) #int, the number of initial deformations, e.g. 7 num_deformations = settings.get('num_deformations', 8) if num_deformations == 1: deformation_fraction[1] = deformation_fraction[0] #bool, run phonon(True) or not(False) phonon = settings.get('phonon', False) #list(3x3), the supercell matrix for phonon, e.g. [[2.0, 0, 0], [0, 2.0, 0], [0, 0, 2.0]] phonon_supercell_matrix = settings.get('phonon_supercell_matrix', None) phonon_supercell_matrix_min = settings.get('phonon_supercell_matrix_min', None) phonon_supercell_matrix_max = settings.get('phonon_supercell_matrix_max', None) optimize_sc = settings.get('optimize_sc', False) #The tolerance for phonon stable stable_tor = settings.get('stable_tor', 0.01) #float, the mimimum of temperature in QHA process, e.g. 5 t_min = settings.get('t_min', 5) #float, the maximum of temperature in QHA process, e.g. 2000 t_max = settings.get('t_max', 2000) #float, the step of temperature in QHA process, e.g. 5 t_step = settings.get('t_step', 5) #float, acceptable value for average RMS, recommend >= 0.005 eos_tolerance = settings.get('eos_tolerance', 0.01) #Global settings for all vasp job, e.g. #override_default_vasp_params = {'user_incar_settings': {}, 'user_kpoints_settings': {}, 'user_potcar_functional': str} #If some value in 'user_incar_settings' is set to None, it will use vasp's default value override_default_vasp_params = settings.get('override_default_vasp_params', {}) #dict, dict of class ModifyIncar with keywords in Workflow name. e.g. modify_incar_params = settings.get('modify_incar_params', {}) #check if fworker_name is assigned powerups = settings.get('powerups', {}) if len(powerups) > 0: if 'user_incar_settings' not in override_default_vasp_params: override_default_vasp_params.update({'user_incar_settings': {}}) override_default_vasp_params['user_incar_settings'].update( {'powerups': powerups}) modify_incar_params.update({'powerups': powerups}) #dict, dict of class ModifyKpoints with keywords in Workflow name, similar with modify_incar_params modify_kpoints_params = settings.get('modify_kpoints_params', {}) #bool, print(True) or not(False) some informations, used for debug verbose = settings.get('verbose', False) #Save the volume data or not ("chgcar", "aeccar0", "aeccar2", "elfcar", "locpot") store_volumetric_data = settings.get('store_volumetric_data', False) if phonon: if isinstance(phonon_supercell_matrix, str): if phonon_supercell_matrix == 'Yphon': phonon_supercell_matrix = supercell_scaling_by_Yphon( structure, supercellsize=phonon_supercell_matrix_max) else: phonon_supercell_matrix = supercell_scaling_by_atom_lat_vol( structure, min_obj=phonon_supercell_matrix_min, max_obj=phonon_supercell_matrix_max, scale_object=phonon_supercell_matrix, target_shape='sc', lower_search_limit=-2, upper_search_limit=2, verbose=verbose, sc_tolerance=1e-5, optimize_sc=optimize_sc) _deformations = _get_deformations(deformation_fraction, num_deformations) if num_deformations > 1: vol_spacing = _deformations[1] - _deformations[0] else: vol_spacing = 0.05 structure = Structure.from_str(POSCAR_STR, fmt='POSCAR') t_kwargs = {'t_min': t_min, 't_max': t_max, 't_step': t_step} common_kwargs = { 'vasp_cmd': vasp_cmd, 'db_file': db_file, "metadata": metadata, "tag": tag, 'override_default_vasp_params': override_default_vasp_params } vasp_kwargs = { 'modify_incar_params': modify_incar_params, 'modify_kpoints_params': modify_kpoints_params } eos_kwargs = { 'deformations': _deformations, 'vol_spacing': vol_spacing, 'eos_tolerance': eos_tolerance, 'threshold': 14 } a_kwargs = { "structure": structure, "settings": settings, "eos_kwargs": eos_kwargs, "static": True, "phonon": phonon, "phonon_supercell_matrix": phonon_supercell_matrix } proc = Crosscom_EVcheck_QHA(verbose=verbose, stable_tor=stable_tor, run_num=0, store_volumetric_data=store_volumetric_data, a_kwargs=a_kwargs, **eos_kwargs, **vasp_kwargs, **t_kwargs, **common_kwargs, test=True) proc.run_task({}) assert False
def test_symmetrize_defect_structure_2(): structure = Structure.from_str(fmt="POSCAR", input_string="""Mg48 N31 1.00000000000000 10.00 0.00 0.00 0.00 10.00 0.00 0.00 0.00 10.00 N 31 Direct 0.9998735951099533 0.9999339271342436 0.9998810782738516 0.4998325344890802 0.0000864604371742 0.0001093145892668 0.9999579188430090 0.5001853666498661 0.0001277381372233 0.2491639910909313 0.2182663238872422 0.4987861655656971 0.2808293379596023 0.4991743721150215 0.7498359204125151 0.5007987323114946 0.2498921962049820 0.2191539974347521 0.2186260754052398 0.4998463318536253 0.2504951842089369 0.5003683092799207 0.7505911171114192 0.2814698995089699 0.7491029691281099 0.2824156531954642 0.4998653178588484 0.2496769296641759 0.2810133141130393 0.0008972384265746 0.2179934993920654 0.0013328906653882 0.7491830895564036 0.9985995146190305 0.2494223137356002 0.2817274775328684 0.2819549960242611 0.0002510594995684 0.2492863143591961 0.9999066837513126 0.7494408251560003 0.2182162389686653 0.7503446162775589 0.2186089947761758 0.0001821657373426 0.5000178504783079 0.5000386610406409 0.9999895875233165 0.4999380720704565 0.5002342427150381 0.5000689317878368 0.0000976472392296 0.5000243131273407 0.5000777225283457 0.5001616481443207 0.0002089601314523 0.4998675396277079 0.7502599885437249 0.7191435719333086 0.9992528941462950 0.7820064323950149 0.9990033992670391 0.2509026823008185 0.0012722293791043 0.7506950871201497 0.7182763220765622 0.7176368346430237 0.9998582962107960 0.7509680009789932 0.0000228430868177 0.2509182464808006 0.7821761073165092 0.2495215811710665 0.7814963684974714 0.9998566240987685 0.7508300518084354 0.7818602560717594 0.5013867902350881 0.7190618878688895 0.5010405127949369 0.2502514755283229 0.4989978969018409 0.7502977850544852 0.7809492219327865 0.7814464623477875 0.5003886730650109 0.7494947707104060 0.4996606931909255 0.2496508616713697 0.7186036919929819 0.2506716727065808 0.7181216545822622 0.5001902272634595""") actual = refine_defect_structure(structure, anchor_atom_index=15, anchor_atom_coords=np.array( [0.5, 0.5, 0.0])) expected = Structure.from_str(fmt="POSCAR", input_string="""Mg4 O3 1.00000000000000 10 0 0 0 10 0 0 0 10 N 31 Direct 0 0 0 0.5 0 0 0 0.5 0 0.249164 0.218235 0.498835 0.280829 0.499143 0.749885 0.500857 0.249885 0.219171 0.218626 0.499815 0.250544 0.500185 0.750544 0.281374 0.749103 0.282384 0.499914 0.249885 0.280829 0.000857 0.218235 0.001165 0.749164 0.998835 0.249164 0.281765 0.282384 8.6e-05 0.249103 0.999914 0.749103 0.217616 0.750544 0.218626 0.000185 0.5 0.5 0 0.5 0.5 0.5 0 0.5 0.5 0.5 1 0.5 0.750115 0.719171 0.999143 0.781765 0.998835 0.250836 0.001165 0.750836 0.718235 0.717616 0.999914 0.750897 8.6e-05 0.250897 0.782384 0.249456 0.781374 0.999815 0.750836 0.781765 0.501165 0.719171 0.500857 0.250115 0.499143 0.750115 0.780829 0.781374 0.500185 0.749456 0.499815 0.249456 0.718626 0.250897 0.717616 0.500086""") assert actual == expected
# TODO: does not support use_fake_vasp yet. VASP will fail. DEBUG_MODE = False POSCAR_STR = """Si2 1.0 3.840198 0.000000 0.000000 1.920099 3.325710 0.000000 0.000000 -2.217138 3.135509 Si 2 direct 0.000000 0.000000 0.000000 Si 0.750000 0.500000 0.750000 Si""" STRUCT = Structure.from_str(POSCAR_STR, fmt='POSCAR') TEST_DIR = os.path.join(MODULE_DIR, 'tmp_fw_test_dir') # LPAD = LaunchPad.from_dict({'host': 'localhost', 'logdir': None, 'name': 'dfttk_unittest', 'password': None, 'port': 27017, 'ssl_ca_file': None, 'strm_lvl': 'DEBUG', 'user_indices': [], 'username': None, 'wf_user_indices': []}) # TODO: enable debug mode by having a launchpad that does not reset # Can this be done by still having other tests pass? # Should we only run one test? # Stop on failure? @pytest.fixture def lpad(): """A LaunchPad object for test instances to use. Always gives a clean (reset) LaunchPad. """ LPAD.reset(None, require_password=False, max_reset_wo_password=5) yield LPAD LPAD.connection.close() return
def add_structure(self, source, name=None, identifier=None, fmt=None): """add a structure to the mpfile""" from pymatgen.core import Structure from pymatgen.ext.matproj import MPRester if isinstance(source, Structure): structure = source elif isinstance(source, dict): structure = Structure.from_dict(source) elif os.path.exists(source): structure = Structure.from_file(source, sort=True) elif isinstance(source, six.string_types): if fmt is None: raise ValueError("Need fmt to get structure from string!") structure = Structure.from_str(source, fmt, sort=True) else: raise ValueError(source, "not supported!") if name is not None: if not isinstance(name, six.string_types): raise ValueError("structure name needs to be a string") elif "." in name: raise ValueError("structure name cannot contain dots (.)") mpr = MPRester() if not mpr.api_key: raise ValueError( "API key not set. Run `pmg config --add PMG_MAPI_KEY <USER_API_KEY>`." ) matched_mpids = mpr.find_structure(structure) formula = get_composition_from_string(structure.composition.formula) if not matched_mpids: if identifier is None: identifier = formula print( "Structure not found in MP! Please submit via MPComplete to " "obtain mp-id or manually choose an anchor mp-id! Continuing " "with {} as identifier!".format(identifier)) else: print("Structure not found in MP! Forcing {} as identifier!". format(identifier)) elif identifier is None: identifier = matched_mpids[0] if len(matched_mpids) > 1: print("Multiple matching structures found in MP. Using", identifier) elif identifier not in matched_mpids: msg = "Structure does not match {} but instead {}!".format( identifier, matched_mpids) raise ValueError(msg) idx = len( self.document.get(identifier, {}).get(mp_level01_titles[3], {})) sub_key = formula if name is None else name if sub_key in self.document.get(identifier, {}).get(mp_level01_titles[3], {}): sub_key += "_{}".format(idx) self.document.rec_update( nest_dict(structure.as_dict(), [identifier, mp_level01_titles[3], sub_key])) return identifier
with open('mp.2019.04.01.json', 'r') as f: structure_data = {i['material_id']: i['structure'] for i in json.load(f)} print('All structures in mp.2019.04.01.json contain %d structures' % len(structure_data)) ## Band gap data with gzip.open('data_no_structs.json.gz', 'rb') as f: bandgap_data = json.loads(f.read()) useful_ids = set.union(*[set(bandgap_data[i].keys()) for i in ALL_FIDELITIES ]) # mp ids that are used in training print('Only %d structures are used' % len(useful_ids)) print('Calculating the graphs for all structures... this may take minutes.') structure_data = {i: structure_data[i] for i in useful_ids} structure_data = { i: crystal_graph.convert(Structure.from_str(j, fmt='cif')) for i, j in structure_data.items() } ## Generate graphs with fidelity information graphs = [] targets = [] material_ids = [] for fidelity_id, fidelity in enumerate(ALL_FIDELITIES): for mp_id in bandgap_data[fidelity]: graph = deepcopy(structure_data[mp_id]) # The fidelity information is included here by changing the state attributes # PBE: 0, GLLB-SC: 1, HSE: 2, SCAN: 3 graph['state'] = [fidelity_id]
tqdm.pandas() # prime progress_apply functionality final_dir = os.path.dirname(os.path.abspath(__file__)) idx_list = [] structs = [] E_vasp_list = [] meta_list = [] ht_paths = [] for f in glob.glob(final_dir + "/raw/*.poscar", recursive=True): task_id = f.split("/")[-1].split(".")[0] with open(f) as s: s = s.read() struct = Structure.from_str(s, fmt="poscar") lines = s.split("\n") num = lines[6].split() E_vasp_per_atom = float(lines[0].split()[0]) / sum(int(a) for a in num) ht_path = lines[0].split()[1] meta_data = "[" + lines[0].split("[")[-1] idx_list.append(task_id) structs.append(struct) E_vasp_list.append(E_vasp_per_atom) ht_paths.append(ht_path) meta_list.append(meta_data)
# load data cif_path = path.normpath(path.join(getcwd(), args.cif_data)) cif_data = h5py.File(cif_path, "r") battery_table = pd.read_csv(args.battery_data, index_col=False) element_data = ElementDataSingleton.get_instance( element_data_path=args.element_data) # create features features = np.zeros((len(battery_table), NUM_OF_FEATURE)) for i, (id_charge, id_discharge, ion) in tqdm( enumerate( zip(battery_table['id_charge'], battery_table['id_discharge'], battery_table['working_ion']))): # load crystal object from cif charge_crystal = Structure.from_str(cif_data[id_charge].value, 'cif') discharge_crystal = Structure.from_str(cif_data[id_discharge].value, 'cif') # specific features finder = SpacegroupAnalyzer(charge_crystal) space_group_feat = np.array([finder.get_space_group_number()]) crystal_system_feat = create_feature_from_crystal_system( finder.get_crystal_system()) ion_feat = create_feature_from_wokring_ion(ion) dischr_comp = Composition(discharge_crystal.formula) ion_concentrate = np.array( [dischr_comp.get_atomic_fraction(Element(ion))]) # calculate features from element property charge_formula = charge_crystal.formula