def test_postfeffset(self): self.mp_xanes.write_input(os.path.join(".", "xanes_3")) feff_dict_input = FEFFDictSet.from_directory(os.path.join(".", "xanes_3")) self.assertTrue( feff_dict_input.tags == Tags.from_file(os.path.join(".", "xanes_3/feff.inp")) ) self.assertTrue( str(feff_dict_input.header()) == str(Header.from_file(os.path.join(".", "xanes_3/HEADER"))) ) feff_dict_input.write_input("xanes_3_regen") origin_tags = Tags.from_file(os.path.join(".", "xanes_3/PARAMETERS")) output_tags = Tags.from_file(os.path.join(".", "xanes_3_regen/PARAMETERS")) origin_mole = Atoms.cluster_from_file(os.path.join(".", "xanes_3/feff.inp")) output_mole = Atoms.cluster_from_file( os.path.join(".", "xanes_3_regen/feff.inp") ) original_mole_dist = np.array(origin_mole.distance_matrix[0, :]).astype( np.float64 ) output_mole_dist = np.array(output_mole.distance_matrix[0, :]).astype( np.float64 ) original_mole_shell = [x.species_string for x in origin_mole] output_mole_shell = [x.species_string for x in output_mole] self.assertTrue(np.allclose(original_mole_dist, output_mole_dist)) self.assertTrue(origin_tags == output_tags) self.assertTrue(original_mole_shell == output_mole_shell) shutil.rmtree(os.path.join(".", "xanes_3")) shutil.rmtree(os.path.join(".", "xanes_3_regen")) reci_mp_xanes = MPXANESSet( self.absorbing_atom, self.structure, user_tag_settings={"RECIPROCAL": ""} ) reci_mp_xanes.write_input("xanes_reci") feff_reci_input = FEFFDictSet.from_directory(os.path.join(".", "xanes_reci")) self.assertTrue("RECIPROCAL" in feff_reci_input.tags) feff_reci_input.write_input("Dup_reci") self.assertTrue(os.path.exists(os.path.join(".", "Dup_reci", "HEADER"))) self.assertTrue(os.path.exists(os.path.join(".", "Dup_reci", "feff.inp"))) self.assertTrue(os.path.exists(os.path.join(".", "Dup_reci", "PARAMETERS"))) self.assertFalse(os.path.exists(os.path.join(".", "Dup_reci", "ATOMS"))) self.assertFalse(os.path.exists(os.path.join(".", "Dup_reci", "POTENTIALS"))) tags_original = Tags.from_file(os.path.join(".", "xanes_reci/feff.inp")) tags_output = Tags.from_file(os.path.join(".", "Dup_reci/feff.inp")) self.assertTrue(tags_original == tags_output) stru_orig = Structure.from_file(os.path.join(".", "xanes_reci/Co2O2.cif")) stru_reci = Structure.from_file(os.path.join(".", "Dup_reci/Co2O2.cif")) self.assertTrue(stru_orig.__eq__(stru_reci)) shutil.rmtree(os.path.join(".", "Dup_reci")) shutil.rmtree(os.path.join(".", "xanes_reci"))
def test_post_distdiff(self): feff_dict_input = FEFFDictSet.from_directory( os.path.join(PymatgenTest.TEST_FILES_DIR, "feff_dist_test")) self.assertTrue(feff_dict_input.tags == Tags.from_file( os.path.join(PymatgenTest.TEST_FILES_DIR, "feff_dist_test/feff.inp"))) self.assertTrue( str(feff_dict_input.header()) == str( Header.from_file( os.path.join(PymatgenTest.TEST_FILES_DIR, "feff_dist_test/HEADER")))) feff_dict_input.write_input("feff_dist_regen") origin_tags = Tags.from_file( os.path.join(PymatgenTest.TEST_FILES_DIR, "feff_dist_test/PARAMETERS")) output_tags = Tags.from_file( os.path.join(".", "feff_dist_regen/PARAMETERS")) origin_mole = Atoms.cluster_from_file( os.path.join(PymatgenTest.TEST_FILES_DIR, "feff_dist_test/feff.inp")) output_mole = Atoms.cluster_from_file( os.path.join(".", "feff_dist_regen/feff.inp")) original_mole_dist = np.array( origin_mole.distance_matrix[0, :]).astype(np.float64) output_mole_dist = np.array(output_mole.distance_matrix[0, :]).astype( np.float64) original_mole_shell = [x.species_string for x in origin_mole] output_mole_shell = [x.species_string for x in output_mole] self.assertTrue(np.allclose(original_mole_dist, output_mole_dist)) self.assertTrue(origin_tags == output_tags) self.assertTrue(original_mole_shell == output_mole_shell) shutil.rmtree(os.path.join(".", "feff_dist_regen"))
def correct(self): backup(FEFF_BACKUP_FILES) feff_input = FEFFDictSet.from_directory(".") scf_values = feff_input.tags.get("SCF") nscmt = scf_values[2] ca = scf_values[3] nmix = scf_values[4] actions = [] #Add RESTART card to PARAMETERS if not "RESTART" in feff_input.tags: actions.append({"dict": "PARAMETERS", "action": {"_set": {"RESTART": []}}}) if nscmt < 100 and ca == 0.2: scf_values[2] = 100 scf_values[4] = 3 # Set nmix = 3 actions.append({"dict": "PARAMETERS", "action": {"_set": {"SCF": scf_values}}}) FeffModder().apply_actions(actions) return {"errors": ["Non-converging job"], "actions": actions} elif nscmt == 100 and nmix == 3 and ca > 0.01: # Reduce the convergence accelerator factor scf_values[3] = round(ca / 2, 2) actions.append({"dict": "PARAMETERS", "action": {"_set": {"SCF": scf_values}}}) FeffModder().apply_actions(actions) return {"errors": ["Non-converging job"], "actions": actions} elif nmix == 3 and ca == 0.01: # Set ca = 0.05 and set nmix scf_values[3] = 0.05 scf_values[4] = 5 actions.append({"dict": "PARAMETERS", "action": {"_set": {"SCF": scf_values}}}) FeffModder().apply_actions(actions) return {"errors": ["Non-converging job"], "actions": actions} elif nmix == 5 and ca == 0.05: # Set ca = 0.05 and set nmix scf_values[3] = 0.05 scf_values[4] = 10 actions.append({"dict": "PARAMETERS", "action": {"_set": {"SCF": scf_values}}}) FeffModder().apply_actions(actions) return {"errors": ["Non-converging job"], "actions": actions} elif nmix == 10 and ca < 0.2: # loop through ca with nmix = 10 scf_values[3] = round(ca * 2, 2) actions.append({"dict": "PARAMETERS", "action": {"_set": {"SCF": scf_values}}}) FeffModder().apply_actions(actions) return {"errors": ["Non-converging job"], "actions": actions} # Unfixable error. Just return None for actions. else: return {"errors": ["Non-converging job"], "actions": None}
def test_postfeffset(self): self.mp_xanes.write_input(os.path.join('.', 'xanes_3')) feff_dict_input = FEFFDictSet.from_directory(os.path.join('.', 'xanes_3')) self.assertTrue(feff_dict_input.tags == Tags.from_file(os.path.join('.', 'xanes_3/feff.inp'))) self.assertTrue(str(feff_dict_input.header()) == str(Header.from_file(os.path.join('.', 'xanes_3/HEADER')))) feff_dict_input.write_input('xanes_3_regen') origin_tags = Tags.from_file(os.path.join('.', 'xanes_3/PARAMETERS')) output_tags = Tags.from_file(os.path.join('.', 'xanes_3_regen/PARAMETERS')) origin_mole = Atoms.cluster_from_file(os.path.join('.', 'xanes_3/feff.inp')) output_mole = Atoms.cluster_from_file(os.path.join('.', 'xanes_3_regen/feff.inp')) original_mole_dist = np.array(origin_mole.distance_matrix[0, :]).astype(np.float64) output_mole_dist = np.array(output_mole.distance_matrix[0, :]).astype(np.float64) original_mole_shell = [x.species_string for x in origin_mole] output_mole_shell = [x.species_string for x in output_mole] self.assertTrue(np.allclose(original_mole_dist, output_mole_dist)) self.assertTrue(origin_tags == output_tags) self.assertTrue(original_mole_shell == output_mole_shell) shutil.rmtree(os.path.join('.', 'xanes_3')) shutil.rmtree(os.path.join('.', 'xanes_3_regen')) reci_mp_xanes = MPXANESSet(self.absorbing_atom, self.structure, user_tag_settings={"RECIPROCAL": ""}) reci_mp_xanes.write_input('xanes_reci') feff_reci_input = FEFFDictSet.from_directory(os.path.join('.', 'xanes_reci')) self.assertTrue("RECIPROCAL" in feff_reci_input.tags) feff_reci_input.write_input('Dup_reci') self.assertTrue(os.path.exists(os.path.join('.', 'Dup_reci', 'HEADER'))) self.assertTrue(os.path.exists(os.path.join('.', 'Dup_reci', 'feff.inp'))) self.assertTrue(os.path.exists(os.path.join('.', 'Dup_reci', 'PARAMETERS'))) self.assertFalse(os.path.exists(os.path.join('.', 'Dup_reci', 'ATOMS'))) self.assertFalse(os.path.exists(os.path.join('.', 'Dup_reci', 'POTENTIALS'))) tags_original = Tags.from_file(os.path.join('.', 'xanes_reci/feff.inp')) tags_output = Tags.from_file(os.path.join('.', 'Dup_reci/feff.inp')) self.assertTrue(tags_original == tags_output) stru_orig = Structure.from_file(os.path.join('.', 'xanes_reci/Co2O2.cif')) stru_reci = Structure.from_file(os.path.join('.', 'Dup_reci/Co2O2.cif')) self.assertTrue(stru_orig.__eq__(stru_reci)) shutil.rmtree(os.path.join('.', 'Dup_reci')) shutil.rmtree(os.path.join('.', 'xanes_reci'))
def __init__(self, actions=None, strict=True, feffinp=None): """ Args: actions ([Action]): A sequence of supported actions. See actions ([Action]): A sequence of supported actions. See :mod:`custodian.ansible.actions`. Default is None, which means DictActions and FileActions are supported. strict (bool): Indicating whether to use strict mode. In non-strict mode, unsupported actions are simply ignored without any errors raised. In strict mode, if an unsupported action is supplied, a ValueError is raised. Defaults to True. feffinp (FEFFInput): A FeffInput object from the current directory. Initialized automatically if not passed (but passing it will avoid having to reparse the directory). """ self.feffinp = feffinp or FEFFDictSet.from_directory(".") self.feffinp = self.feffinp.all_input() actions = actions or [FileActions, DictActions] super().__init__(actions, strict)
def test_post_distdiff(self): feff_dict_input = FEFFDictSet.from_directory(os.path.join(test_dir, 'feff_dist_test')) self.assertTrue(feff_dict_input.tags == Tags.from_file(os.path.join(test_dir, 'feff_dist_test/feff.inp'))) self.assertTrue( str(feff_dict_input.header()) == str(Header.from_file(os.path.join(test_dir, 'feff_dist_test/HEADER')))) feff_dict_input.write_input('feff_dist_regen') origin_tags = Tags.from_file(os.path.join(test_dir, 'feff_dist_test/PARAMETERS')) output_tags = Tags.from_file(os.path.join('.', 'feff_dist_regen/PARAMETERS')) origin_mole = Atoms.cluster_from_file(os.path.join(test_dir, 'feff_dist_test/feff.inp')) output_mole = Atoms.cluster_from_file(os.path.join('.', 'feff_dist_regen/feff.inp')) original_mole_dist = np.array(origin_mole.distance_matrix[0, :]).astype(np.float64) output_mole_dist = np.array(output_mole.distance_matrix[0, :]).astype(np.float64) original_mole_shell = [x.species_string for x in origin_mole] output_mole_shell = [x.species_string for x in output_mole] self.assertTrue(np.allclose(original_mole_dist, output_mole_dist)) self.assertTrue(origin_tags == output_tags) self.assertTrue(original_mole_shell == output_mole_shell) shutil.rmtree(os.path.join('.', 'feff_dist_regen'))
def __init__(self, actions=None, strict=True, feffinp=None): """ Initializes a Modder for FeffInput sets Args: actions ([Action]): A sequence of supported actions. See actions ([Action]): A sequence of supported actions. See :mod:`custodian.ansible.actions`. Default is None, which means DictActions and FileActions are supported. strict (bool): Indicating whether to use strict mode. In non-strict mode, unsupported actions are simply ignored without any errors raised. In strict mode, if an unsupported action is supplied, a ValueError is raised. Defaults to True. feffinp (FEFFInput): A FeffInput object from the current directory. Initialized automatically if not passed (but passing it will avoid having to reparse the directory). """ self.feffinp = feffinp or FEFFDictSet.from_directory('.') self.feffinp = self.feffinp.all_input() actions = actions or [FileActions, DictActions] super(FeffModder, self).__init__(actions, strict)
def correct(self): backup(FEFF_BACKUP_FILES) feff_input = FEFFDictSet.from_directory(".") scf_values = feff_input.tags.get("SCF") nscmt = scf_values[2] ca = scf_values[3] nmix = scf_values[4] actions = [] if nscmt < 100 and ca == 0.2: scf_values[2] = 100 scf_values[4] = 3 # Set nmix = 3 actions.append({ "dict": "PARAMETERS", "action": { "_set": { "SCF": scf_values } } }) FeffModder().apply_actions(actions) return {"errors": ["Non-converging job"], "actions": actions} elif nscmt == 100 and nmix == 3 and ca > 0.01: # Reduce the convergence accelerator factor scf_values[3] = round(ca / 2, 2) actions.append({ "dict": "PARAMETERS", "action": { "_set": { "SCF": scf_values } } }) FeffModder().apply_actions(actions) return {"errors": ["Non-converging job"], "actions": actions} elif nmix == 3 and ca == 0.01: # Set ca = 0.05 and set nmix scf_values[3] = 0.05 scf_values[4] = 5 actions.append({ "dict": "PARAMETERS", "action": { "_set": { "SCF": scf_values } } }) FeffModder().apply_actions(actions) return {"errors": ["Non-converging job"], "actions": actions} elif nmix == 5 and ca == 0.05: # Set ca = 0.05 and set nmix scf_values[3] = 0.05 scf_values[4] = 10 actions.append({ "dict": "PARAMETERS", "action": { "_set": { "SCF": scf_values } } }) FeffModder().apply_actions(actions) return {"errors": ["Non-converging job"], "actions": actions} elif nmix == 10 and ca < 0.2: # loop through ca with nmix = 10 scf_values[3] = round(ca * 2, 2) actions.append({ "dict": "PARAMETERS", "action": { "_set": { "SCF": scf_values } } }) FeffModder().apply_actions(actions) return {"errors": ["Non-converging job"], "actions": actions} # Unfixable error. Just return None for actions. else: return {"errors": ["Non-converging job"], "actions": None}