From 9a1bcf7c433a060932e3ee77f2764e519e1a2a39 Mon Sep 17 00:00:00 2001 From: Sarath Menon Date: Wed, 11 Oct 2023 09:06:01 +0200 Subject: [PATCH] add dumping for fe mode# --- calphy/composition_transformation.py | 61 ++++------------------------ calphy/input.py | 4 +- calphy/solid.py | 14 +++++++ examples/example_10/input3.yaml | 5 +-- 4 files changed, 26 insertions(+), 58 deletions(-) diff --git a/calphy/composition_transformation.py b/calphy/composition_transformation.py index 2288ebc..a0f9b46 100644 --- a/calphy/composition_transformation.py +++ b/calphy/composition_transformation.py @@ -29,6 +29,7 @@ from mendeleev import element from ase.io import read, write from ase.atoms import Atoms +from pyscal3.core import element_dict class CompositionTransformation: """ @@ -112,11 +113,10 @@ class CompositionTransformation: """ def __init__(self, calc): - self.structure = self.prepare_structure(calc) - self.input_chemical_composition = calc.composition_scaling.input_chemical_composition + self.input_chemical_composition = calc.composition_scaling._input_chemical_composition self.output_chemical_composition = calc.composition_scaling.output_chemical_composition self.restrictions = calc.composition_scaling.restrictions - + self.calc = calc self.actual_species = None self.new_species = None self.maxtype = None @@ -133,31 +133,6 @@ def dict_to_string(self, inputdict): strlst.append(str(val)) return "".join(strlst) - def is_data_file(self, filename): - try: - atoms = read(filename, format="lammps-data", style="atomic") - return atoms - except: - return None - - def is_dump_file(self, filename): - try: - atoms = read(filename, format="lammps-dump-text") - return atoms - except: - return None - - def prepare_structure(self, input_structure): - """ - Check the format of a given input file and validate it. - """ - if isinstance(input_structure, Atoms): - return input_structure - elif os.path.exists(input_structure): - atoms = self.is_data_file(input_structure) - if atoms is None: - atoms = self.is_dump_file(input_structure) - return atoms def convert_to_pyscal(self): """ @@ -171,20 +146,8 @@ def convert_to_pyscal(self): types, typecounts = np.unique(typelist, return_counts=True) composition = {types[x]: typecounts[x] for x in range(len(types))} - atomsymbols = [] - atomtypes = [] - for key, val in self.input_chemical_composition.items(): - if not val==0: - found = False - for key1, val1 in composition.items(): - if val1==val: - found = True - atomsymbols.append(key) - atomtypes.append(int(key1)) - del composition[key1] - break - if not found: - raise ValueError("Input structure and composition do not match!") + atomsymbols = self.calc.element + atomtypes = [x+1 for x in range(len(self.calc.element))] self.pyscal_structure = pstruct self.typedict = dict(zip(atomsymbols, atomtypes)) @@ -196,14 +159,6 @@ def convert_to_pyscal(self): self.maxtype = self.actual_species + 1 #+ self.new_species #print(self.typedict) - def check_if_atoms_conserved(self): - """ - Check if a given transformation is possible by checking if number of atoms are conserved - """ - natoms1 = np.sum([val for key, val in self.input_chemical_composition.items()]) - natoms2 = np.sum([val for key, val in self.output_chemical_composition.items()]) - if not (natoms1==natoms2==self.natoms): - raise ValueError(f"Input and output number of atoms are not conserved! Input {self.dict_to_string(self.input_chemical_composition)}, output {self.dict_to_string(self.output_chemical_composition)}, total atoms in structure {self.natoms}") def get_composition_transformation(self): """ @@ -378,7 +333,10 @@ def update_pair_coeff(self, pair_coeff): return pc_old, pc_new def write_structure(self, outfilename): - self.pyscal_structure.write.file(outfilename, format='lammps-data') + self.pyscal_structure.write.file(outfilename, format='lammps-dump') + #read it back in with ase + + def prepare_mappings(self): self.atom_mark = [] @@ -388,7 +346,6 @@ def prepare_mappings(self): self.get_composition_transformation() self.convert_to_pyscal() - self.check_if_atoms_conserved() self.mark_atoms() self.update_mark_atoms() diff --git a/calphy/input.py b/calphy/input.py index aa9d5df..bfef0aa 100644 --- a/calphy/input.py +++ b/calphy/input.py @@ -65,7 +65,7 @@ class CompositionScaling(BaseModel, title='Composition scaling input options'): _input_chemical_composition: PrivateAttr(default=None) output_chemical_composition: Annotated[dict, Field(default=None, required=False)] restrictions: Annotated[List[str], BeforeValidator(to_list), - Field(default=None, required=False)] + Field(default=[], required=False)] class MD(BaseModel, title='MD specific input options'): timestep: Annotated[float, Field(default=0.001, @@ -404,7 +404,7 @@ def _validate_comp_scaling(self) -> 'Input': #we also should check if actual contents are present input_chem_comp = {} for key, val in self._element_dict.items(): - input_chem_comp[key] = val + input_chem_comp[key] = val['count'] self.composition_scaling._input_chemical_composition = input_chem_comp #now we should check output chem comp and see there are no keys extra diff --git a/calphy/solid.py b/calphy/solid.py index 6088996..65ab2a6 100644 --- a/calphy/solid.py +++ b/calphy/solid.py @@ -438,10 +438,17 @@ def run_integration(self, iteration=1): command = str1 + str2 + str3 lmp.command(command) + if self.calc.n_print_steps > 0: + lmp.command("dump d1 all custom %d traj.fe.forward_%d.dat id type mass x y z fx fy fz"%(self.calc.n_print_steps, + iteration)) + #Forward switching over ts steps lmp.command("run %d"%self.calc._n_switching_steps) lmp.command("unfix f4") + if self.calc.n_print_steps > 0: + lmp.command("undump d1") + #Equilibriate lmp.command("run %d"%self.calc.n_equilibration_steps) @@ -456,10 +463,17 @@ def run_integration(self, iteration=1): command = str1 + str2 + str3 lmp.command(command) + if self.calc.n_print_steps > 0: + lmp.command("dump d1 all custom %d traj.fe.backward_%d.dat id type mass x y z fx fy fz"%(self.calc.n_print_steps, + iteration)) + #Reverse switching over ts steps lmp.command("run %d"%self.calc._n_switching_steps) lmp.command("unfix f4") + if self.calc.n_print_steps > 0: + lmp.command("undump d1") + #close object if not self.calc.script_mode: lmp.close() diff --git a/examples/example_10/input3.yaml b/examples/example_10/input3.yaml index 2992746..a330259 100644 --- a/examples/example_10/input3.yaml +++ b/examples/example_10/input3.yaml @@ -1,11 +1,8 @@ calculations: - composition_scaling: - input_chemical_composition: + output_chemical_composition: Cu: 122 Zr: 128 - output_chemical_composition: - Cu: 128 - Zr: 122 element: - Zr - Cu