Skip to content

Commit

Permalink
add dumping for fe mode#
Browse files Browse the repository at this point in the history
  • Loading branch information
srmnitc committed Oct 11, 2023
1 parent b7ad13e commit 9a1bcf7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 58 deletions.
61 changes: 9 additions & 52 deletions calphy/composition_transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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
Expand All @@ -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):
"""
Expand All @@ -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))
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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 = []
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions calphy/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions calphy/solid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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()
Expand Down
5 changes: 1 addition & 4 deletions examples/example_10/input3.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 9a1bcf7

Please sign in to comment.