Skip to content

Commit

Permalink
Continue to condense engines
Browse files Browse the repository at this point in the history
Based on @liamhuber 's initial work in #170
  • Loading branch information
jan-janssen committed Jan 5, 2024
1 parent 85e0f54 commit 3fd86ef
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 63 deletions.
41 changes: 18 additions & 23 deletions atomistics/calculators/ase.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,53 +29,48 @@ def __init__(self, ase_structure, ase_calculator):
self.structure = ase_structure
self.structure.calc = ase_calculator

def get_forces(self):
def forces(self):
return self.structure.get_forces()

def get_energy(self):
def energy(self):
return self.structure.get_potential_energy()

def get_stress(self):
return self.structure.get_stress(voigt=False)
def energy_pot(self):
return self.structure.get_potential_energy()

def get_total_energy(self):
def energy_tot(self):
return (
self.structure.get_potential_energy() + self.structure.get_kinetic_energy()
)

def get_cell(self):
def stress(self):
return self.structure.get_stress(voigt=False)

def pressure(self):
return self.structure.get_stress(voigt=False)

def cell(self):
return self.structure.get_cell()

def get_positions(self):
def positions(self):
return self.structure.get_positions()

def get_velocities(self):
def velocities(self):
return self.structure.get_velocities()

def get_temperature(self):
def temperature(self):
return self.structure.get_temperature()

def get_volume(self):
def volume(self):
return self.structure.get_volume()


ASEOutputStatic = OutputStatic(
forces=ASEExecutor.get_forces,
energy=ASEExecutor.get_energy,
stress=ASEExecutor.get_stress,
volume=ASEExecutor.get_volume,
**{k: getattr(ASEExecutor, k) for k in OutputStatic.fields()}
)

ASEOutputMolecularDynamics = OutputMolecularDynamics(
positions=ASEExecutor.get_positions,
cell=ASEExecutor.get_cell,
forces=ASEExecutor.get_forces,
temperature=ASEExecutor.get_temperature,
energy_pot=ASEExecutor.get_energy,
energy_tot=ASEExecutor.get_total_energy,
pressure=ASEExecutor.get_stress,
velocities=ASEExecutor.get_velocities,
volume=ASEExecutor.get_volume,
**{k: getattr(ASEExecutor, k) for k in OutputMolecularDynamics.fields()}
)


Expand Down
16 changes: 6 additions & 10 deletions atomistics/workflows/evcurve/debye.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ def __init__(
)
self._constant_volume = constant_volume

def get_free_energy(self):
def free_energy(self):
return (
self._pes.get_free_energy_p()
- self._debye_model.interpolate(volumes=self._pes.get_minimum_energy_path())
) / self._pes.num_atoms

def get_temperatures(self):
def temperatures(self):
return self._temperatures

def get_entropy(self):
def entropy(self):
if not self._constant_volume:
return (
self._pes.eV_to_J_per_mol
Expand All @@ -54,7 +54,7 @@ def get_entropy(self):
* self._pes.get_entropy_v()
)

def get_heat_capacity(self):
def heat_capacity(self):
if not self._constant_volume:
heat_capacity = (
self._pes.eV_to_J_per_mol
Expand All @@ -69,19 +69,15 @@ def get_heat_capacity(self):
)
return np.array(heat_capacity.tolist() + [np.nan, np.nan])

def get_volumes(self):
def volumes(self):
if not self._constant_volume:
return self._pes.get_minimum_energy_path()
else:
return np.array([self._pes.volumes[0]] * len(self._temperatures))


DebyeOutputThermodynamic = OutputThermodynamic(
temperatures=DebyeThermalProperties.get_temperatures,
free_energy=DebyeThermalProperties.get_free_energy,
entropy=DebyeThermalProperties.get_entropy,
heat_capacity=DebyeThermalProperties.get_heat_capacity,
volumes=DebyeThermalProperties.get_volumes,
**{k: getattr(DebyeThermalProperties, k) for k in OutputThermodynamic.fields()}
)


Expand Down
32 changes: 12 additions & 20 deletions atomistics/workflows/phonons/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def _calc_force_constants(self):
)
self._force_constants = self._phonopy.force_constants

def get_mesh_dict(self):
def mesh_dict(self):
if self._force_constants is None:
self._calc_force_constants()
if self._mesh_dict is None:
Expand All @@ -89,12 +89,12 @@ def get_mesh_dict(self):
self._mesh_dict = self._phonopy.get_mesh_dict()
return self._mesh_dict

def get_band_structure_dict(self):
def band_structure_dict(self):
if self._band_structure_dict is None:
self._calc_band_structure()
return self._band_structure_dict

def get_total_dos_dict(self):
def total_dos_dict(self):
if self._total_dos is None:
self._phonopy.run_total_dos(
sigma=self._sigma,
Expand All @@ -106,12 +106,12 @@ def get_total_dos_dict(self):
self._total_dos = self._phonopy.get_total_dos_dict()
return self._total_dos

def get_dynamical_matrix(self):
def dynamical_matrix(self):
if self._band_structure_dict is None:
self._calc_band_structure()
return self._phonopy.dynamical_matrix.dynamical_matrix

def get_force_constants(self):
def force_constants(self):
if self._force_constants is None:
self._calc_force_constants()
return self._force_constants
Expand All @@ -122,38 +122,30 @@ def __init__(self, phonopy_instance):
self._phonopy = phonopy_instance
self._thermal_properties = phonopy_instance.get_thermal_properties_dict()

def get_free_energy(self):
def free_energy(self):
return self._thermal_properties["free_energy"] * kJ_mol_to_eV

def get_temperatures(self):
def temperatures(self):
return self._thermal_properties["temperatures"]

def get_entropy(self):
def entropy(self):
return self._thermal_properties["entropy"]

def get_heat_capacity(self):
def heat_capacity(self):
return self._thermal_properties["heat_capacity"]

def get_volumes(self):
def volumes(self):
return np.array(
[self._phonopy.unitcell.get_volume()]
* len(self._thermal_properties["temperatures"])
)


PhonopyOutputPhonons = OutputPhonons(
mesh_dict=PhonopyProperties.get_mesh_dict,
band_structure_dict=PhonopyProperties.get_band_structure_dict,
total_dos_dict=PhonopyProperties.get_total_dos_dict,
dynamical_matrix=PhonopyProperties.get_dynamical_matrix,
force_constants=PhonopyProperties.get_force_constants,
**{k: getattr(PhonopyProperties, k) for k in OutputPhonons.fields()}
)
PhonopyOutputThermodynamic = OutputThermodynamic(
temperatures=PhonopyThermalProperties.get_temperatures,
free_energy=PhonopyThermalProperties.get_free_energy,
entropy=PhonopyThermalProperties.get_entropy,
heat_capacity=PhonopyThermalProperties.get_heat_capacity,
volumes=PhonopyThermalProperties.get_volumes,
**{k: getattr(PhonopyThermalProperties, k) for k in OutputThermodynamic.fields()}
)


Expand Down
16 changes: 6 additions & 10 deletions atomistics/workflows/quasiharmonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,28 +258,24 @@ def get_property(self, thermal_property):
]
)

def get_free_energy(self):
def free_energy(self):
return self.get_property(thermal_property="free_energy")

def get_temperatures(self):
def temperatures(self):
return self._temperatures

def get_entropy(self):
def entropy(self):
return self.get_property(thermal_property="entropy")

def get_heat_capacity(self):
def heat_capacity(self):
return self.get_property(thermal_property="heat_capacity")

def get_volumes(self):
def volumes(self):
return self._volumes_selected_lst


QuasiHarmonicOutputThermodynamic = OutputThermodynamic(
temperatures=QuasiHarmonicThermalProperties.get_temperatures,
free_energy=QuasiHarmonicThermalProperties.get_free_energy,
entropy=QuasiHarmonicThermalProperties.get_entropy,
heat_capacity=QuasiHarmonicThermalProperties.get_heat_capacity,
volumes=QuasiHarmonicThermalProperties.get_volumes,
**{k: getattr(QuasiHarmonicThermalProperties, k) for k in OutputThermodynamic.fields()}
)


Expand Down

0 comments on commit 3fd86ef

Please sign in to comment.