Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.1relax linguist-detectable=false
*.2relax linguist-detectable=false
*.3static linguist-detectable=false
20 changes: 0 additions & 20 deletions LICENSE

This file was deleted.

21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 Nigel Lee En Hew

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
159 changes: 36 additions & 123 deletions examples/codespace/Fe3Pt.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@
"4. You are now ready to run the cells below!"
]
},
{
"cell_type": "markdown",
"id": "9ae53c39",
"metadata": {},
"source": [
"# Install pyzentropy in editable mode"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "124181fd",
"metadata": {},
"outputs": [],
"source": [
"!cd ../../ && pip install -e ."
]
},
{
"cell_type": "markdown",
"id": "8de285bd",
Expand Down Expand Up @@ -85,20 +103,7 @@
"source": [
"# PyZentropy Configuration Objects\n",
"\n",
"This section constructs PyZentropy `Configuration` objects for each Fe₃Pt configuration. Properties at 0 K are excluded to avoid division by zero errors. For each configuration, internal energies and partition functions are calculated."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "eba55270",
"metadata": {},
"outputs": [],
"source": [
"# Extract basic properties from the reference configuration\n",
"number_of_atoms = input[\"FM\"]['number_of_atoms']\n",
"volumes = input[\"FM\"]['volumes']\n",
"temperatures = input[\"FM\"]['temperatures'] "
"This section constructs PyZentropy `Configuration` objects for each Fe₃Pt configuration. For each configuration, the internal energies are calculated automatically."
]
},
{
Expand All @@ -118,38 +123,19 @@
" config_objects[config_name] = Configuration(\n",
" name=config_name,\n",
" multiplicity=config['multiplicity'],\n",
" number_of_atoms=number_of_atoms,\n",
" volumes=volumes,\n",
" temperatures=temperatures,\n",
" number_of_atoms=config['number_of_atoms'],\n",
" volumes=config['volumes'],\n",
" temperatures=config['temperatures'],\n",
" # Extract Helmholtz energies and their derivatives from DFTTK results\n",
" helmholtz_energies=config['helmholtz_energy'],\n",
" helmholtz_energies_dV=config['helmholtz_energy_dV'],\n",
" helmholtz_energies_d2V2=config['helmholtz_energy_d2V2'],\n",
" helmholtz_energies=config['helmholtz_energies'],\n",
" helmholtz_energies_dV=config['helmholtz_energies_dV'],\n",
" helmholtz_energies_d2V2=config['helmholtz_energies_d2V2'],\n",
" # Extract entropy and heat capacity data\n",
" entropies=config['entropy'],\n",
" heat_capacities=config['heat_capacity']\n",
" entropies=config['entropies'],\n",
" heat_capacities=config['heat_capacities']\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3e1b202a",
"metadata": {},
"outputs": [],
"source": [
"# Calculate internal energies for each configuration\n",
"for config in config_objects.values():\n",
" config.calculate_internal_energies()\n",
"\n",
"# Use the ground state configuration as reference for partition function calculations\n",
"reference_helmholtz_energy = config_objects[\"FM\"].helmholtz_energies\n",
"\n",
"# Calculate partition functions for each configuration using the reference energy\n",
"for config in config_objects.values():\n",
" config.calculate_partition_functions(reference_helmholtz_energy)"
]
},
{
"cell_type": "markdown",
"id": "2979bf50",
Expand Down Expand Up @@ -177,7 +163,7 @@
"metadata": {},
"outputs": [],
"source": [
"config_objects[\"FM\"].plot(\"helmholtz_energy_vs_volume\")"
"config_objects[\"FM\"].plot_vt(\"helmholtz_energy_vs_volume\")"
]
},
{
Expand All @@ -190,7 +176,7 @@
"# You can also plot for selected temperatures by passing an array of temperatures.\n",
"# The code will automatically find and use the closest available temperatures.\n",
"selected_temperatures = np.array([100, 300, 600, 900])\n",
"config_objects[\"FM\"].plot(\"helmholtz_energy_vs_volume\", selected_temperatures=selected_temperatures)"
"config_objects[\"FM\"].plot_vt(\"helmholtz_energy_vs_volume\", selected_temperatures=selected_temperatures)"
]
},
{
Expand All @@ -202,8 +188,8 @@
"source": [
"# You can also plot for selected volumes by passing an array of volumes.\n",
"# The code will automatically find and use the closest available volumes.\n",
"selected_volumes = np.array([100, 120, 140, 160])\n",
"config_objects[\"FM\"].plot(\"helmholtz_energy_vs_temperature\", selected_volumes=selected_volumes)"
"selected_volumes = np.array([136, 140, 160])\n",
"config_objects[\"FM\"].plot_vt(\"helmholtz_energy_vs_temperature\", selected_volumes=selected_volumes)"
]
},
{
Expand All @@ -224,17 +210,7 @@
"outputs": [],
"source": [
"# Create a System object from the configuration objects\n",
"system = System(config_objects)\n",
"\n",
"# Perform thermodynamic calculations for the system\n",
"system.calculate_partition_functions()\n",
"system.calculate_probabilities()\n",
"system.calculate_helmholtz_energies(reference_helmholtz_energy)\n",
"system.calculate_entropies()\n",
"system.calculate_helmholtz_energies_dV()\n",
"system.calculate_bulk_moduli()\n",
"system.calculate_helmholtz_energies_d2V2()\n",
"system.calculate_heat_capacities()"
"system = System(config_objects, ground_state=\"FM\")"
]
},
{
Expand All @@ -246,15 +222,15 @@
"source": [
"# Calculate phase diagrams with specified ground state configuration. \n",
"# This also calculates all the properties at constant pressure.\n",
"system.calculate_phase_diagrams(ground_state=\"FM\")"
"system.calculate_phase_diagrams()"
]
},
{
"cell_type": "markdown",
"id": "dc6c34ee",
"metadata": {},
"source": [
"The following are example plots vs. volume or temperature. For all of these plots, you can plot for `selected_temperatures` and `selected_volumes`. The available plots are:\n",
"The following are example plots vs. volume or temperature. For all of these plots (apart from vt_phase_diagram), you can plot for `selected_temperatures` and `selected_volumes`. The available plots are:\n",
"\n",
"**Helmholtz Energy**\n",
"- \"helmholtz_energy_vs_volume\"\n",
Expand Down Expand Up @@ -292,36 +268,6 @@
"system.plot_vt(\"helmholtz_energy_vs_volume\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4f4b7ab4",
"metadata": {},
"outputs": [],
"source": [
"system.plot_vt(\"entropy_vs_temperature\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "987276f9",
"metadata": {},
"outputs": [],
"source": [
"system.plot_vt(\"heat_capacity_vs_temperature\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2f736a5a",
"metadata": {},
"outputs": [],
"source": [
"system.plot_vt(\"bulk_modulus_vs_temperature\")"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -337,7 +283,7 @@
"id": "678a6f4f",
"metadata": {},
"source": [
"The following are example plots for properties at constant pressure. The available plots are:\n",
"The following are example plots for properties at constant pressure. You can plot for `selected_temperatures` for helmholtz_energy_pv_vs_volume. The available plots are:\n",
"\n",
"- \"probability_vs_temperature\"\n",
"- \"helmholtz_energy_pv_vs_volume\"\n",
Expand Down Expand Up @@ -369,30 +315,7 @@
"metadata": {},
"outputs": [],
"source": [
"system.plot_pt(\"probability_vs_temperature\", ground_state=\"FM\", P=0)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2a171cbd",
"metadata": {},
"outputs": [],
"source": [
"system.plot_pt(\"helmholtz_energy_pv_vs_volume\", P=0)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1ca0418c",
"metadata": {},
"outputs": [],
"source": [
"# You can also plot for selected temperatures by passing an array of temperatures.\n",
"# The code will automatically find and use the closest available temperatures.\n",
"selected_temperatures = np.array([100, 300, 600, 900])\n",
"system.plot_pt(\"helmholtz_energy_pv_vs_volume\", P=0, selected_temperatures=selected_temperatures)"
"system.plot_pt(\"probability_vs_temperature\", P=0)"
]
},
{
Expand Down Expand Up @@ -434,16 +357,6 @@
"source": [
"system.plot_pt(\"heat_capacity_vs_temperature\", P=0)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bb30e4e6",
"metadata": {},
"outputs": [],
"source": [
"system.plot_pt(\"gibbs_energy_vs_temperature\", P=0)"
]
}
],
"metadata": {
Expand Down
Binary file modified examples/codespace/Fe3Pt_input.pkl
Binary file not shown.
28 changes: 0 additions & 28 deletions pyzentropy/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ def __init__(
helmholtz_energies: np.ndarray,
helmholtz_energies_dV: np.ndarray,
helmholtz_energies_d2V2: np.ndarray,
reference_helmholtz_energies: np.ndarray,
entropies: np.ndarray = None,
heat_capacities: np.ndarray = None,
):
Expand Down Expand Up @@ -139,39 +138,12 @@ def __init__(
if self.entropies is not None:
self.calculate_internal_energies()

# Always calculate partition functions using the provided reference Helmholtz energies
self.calculate_partition_functions(reference_helmholtz_energies)

def calculate_internal_energies(self) -> None:
"""
Calculate internal energies using the formula: E = F + T*S.
"""
self.internal_energies = self.helmholtz_energies + self.temperatures[:, np.newaxis] * self.entropies

def calculate_partition_functions(self, reference_helmholtz_energies: np.ndarray) -> None:
"""
Calculate the partition function for each state, using a reference Helmholtz energy using the formula: Z = exp(-(F - F_ref) / (k_B * T)).

Args:
reference_helmholtz_energies (np.ndarray): Reference Helmholtz energies to shift by (shape: [n_temperatures, n_volumes])

Raises:
ValueError: If reference_helmholtz_energies does not match the expected shape.
"""

if reference_helmholtz_energies.shape != (len(self.temperatures), len(self.volumes)):
raise ValueError(
f"reference_helmholtz_energies must have shape {(len(self.temperatures), len(self.volumes))} "
f"Received array with shape {reference_helmholtz_energies.shape}."
)

helmholtz_energy_shifted = self.helmholtz_energies - reference_helmholtz_energies
exponent = -helmholtz_energy_shifted / (BOLTZMANN_CONSTANT * self.temperatures[:, np.newaxis])
with np.errstate(over="ignore"):
partition_functions = np.exp(exponent)
partition_functions[np.isinf(partition_functions)] = np.nan
self.partition_functions = partition_functions

def plot_vt(
self,
type: str,
Expand Down
Loading
Loading