Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remake dopedxpy-sc-fermi #46

Open
wants to merge 95 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
a2b82a7
remake dopedxpy-sc-fermi
alexsquires Jan 10, 2024
305bd24
implement full functionalility from SK thesis
alexsquires Jan 11, 2024
c76ec9f
supress py-sc-fermi warnings
alexsquires Jan 11, 2024
5a94f0d
basic tutorial, full data with CdTe and we can polish it off
alexsquires Jan 11, 2024
0cf411e
test py-sc-fermi interface
alexsquires Jan 11, 2024
cf5764f
start work on new integrated solver
alexsquires Feb 9, 2024
f35720d
example files
alexsquires Feb 9, 2024
a6f739b
Merge branch 'develop' of https://github.com/SMTG-Bham/doped into dop…
alexsquires Feb 9, 2024
39b00d6
remake interface
alexsquires Feb 14, 2024
b8b9e24
merge upstream changes
alexsquires Feb 15, 2024
8079583
fix up CdTe example data
alexsquires Feb 15, 2024
1787c8e
improve py_sc_fermi tutorial
alexsquires Feb 15, 2024
fa4b1f2
update pyscfermi interface
alexsquires Feb 15, 2024
467842b
add effective dopant scanning
alexsquires Feb 15, 2024
e2b39e7
fill out exceptions and effective dopant concentrations
alexsquires Feb 15, 2024
bbbccc5
tutorials for exceptions and effective dopant concentrations
alexsquires Feb 15, 2024
2880f12
update tests
alexsquires Feb 15, 2024
6166358
add chemical potential grid search
alexsquires Feb 23, 2024
a787edb
significant code redundancy reductions
alexsquires Feb 23, 2024
a841f0b
finish minimal redudnacy refactor
alexsquires Feb 26, 2024
a18f472
implement iterative grid solver
alexsquires Feb 26, 2024
365bee4
tutorials
alexsquires Feb 27, 2024
f8cfdb8
prep for testing
alexsquires Feb 27, 2024
33ea80f
base testing
alexsquires Feb 27, 2024
0eea464
Merge branch 'develop' into dopey_fermi
kavanase Mar 11, 2024
ee6c987
Fix corrupted JSON file
kavanase Mar 11, 2024
38c7956
Add `py-sc-fermi` interface tutorial to docs
kavanase Mar 11, 2024
5edcfcc
Update `fermi_solver.py`; run import checks and warning only when `py…
kavanase Mar 11, 2024
c9b8c98
Resolve `TODO` in `thermodynamics`
kavanase Mar 11, 2024
1c14487
Update tutorial notebook
kavanase Mar 11, 2024
b6ac3c4
Cleanup and gzip vaspruns for space
kavanase Mar 13, 2024
0371f33
Suggested: Refactor `fix_defect_species` to `fix_charge_states` as th…
kavanase Mar 13, 2024
616126a
Make `_get_chempot_term` far more efficient (realised was bottleneck …
kavanase Mar 13, 2024
9901b68
Add `effective_dopant_concentration` parameter to `doped` thermodynam…
kavanase Mar 13, 2024
c5a25e1
Add `effective_dopant_concentration` parameter to `FermiSolverDoped` …
kavanase Mar 13, 2024
ac6fa81
Update tutorial
kavanase Mar 13, 2024
904c13d
defualt multiplicity factor handling
alexsquires Mar 20, 2024
9d079b6
change to
alexsquires Mar 20, 2024
c6d8835
add docstrings
alexsquires Mar 20, 2024
f148528
linting
alexsquires Apr 2, 2024
326ddf1
fix the default chempot behaviour
alexsquires Apr 2, 2024
f781401
Merge branch 'develop' into dopey_fermi
kavanase Apr 5, 2024
f4249bd
Merge branch 'develop' into dopey_fermi
kavanase Apr 6, 2024
9116335
Merge branch 'refs/heads/develop' into dopey_fermi
kavanase Apr 10, 2024
a37a08f
Merge branch 'refs/heads/develop' into dopey_fermi
kavanase Apr 11, 2024
de94129
Merge branch 'refs/heads/develop' into dopey_fermi
kavanase May 13, 2024
91850c5
supress warnings
alexsquires May 22, 2024
9d90b7a
Fix (most) failing tests, formatting, match other test preferences (`…
kavanase May 22, 2024
84ce2ee
supress py_sc_fermi warnings
alexsquires Jul 9, 2024
9d8686f
Merge remote-tracking branch 'origin' into dopey_fermi
alexsquires Jul 11, 2024
54b73a0
add limits as option to most scans
alexsquires Jul 11, 2024
723eaf4
minor tutorial update
alexsquires Jul 11, 2024
0d495d6
Merge branch 'refs/heads/develop' into dopey_fermi
kavanase Jul 11, 2024
974c23d
Merge and formatting
kavanase Jul 11, 2024
b0b2047
Merge branch 'refs/heads/develop' into dopey_fermi
kavanase Jul 11, 2024
27ec104
Use `_parse_chempots` function from `doped.thermodynamics` for cleane…
kavanase Jul 12, 2024
853c93f
Cleanup; remove unused `suppress_warnings` etc
kavanase Jul 12, 2024
ba1519f
Tutorial updates and minor code cleanup
kavanase Jul 12, 2024
8d7723a
Update `DefectThermodynamics` paths in `FermiSolver` tests
kavanase Jul 12, 2024
81144a9
explicitly add in vertices to grid searches
alexsquires Jul 30, 2024
761dab5
merge
alexsquires Jul 30, 2024
17bfdf2
Merge branch 'refs/heads/develop' into dopey_fermi
kavanase Jul 30, 2024
719ae56
black
alexsquires Jul 31, 2024
9fab44b
update docstrings and example notebook
alexsquires Jul 31, 2024
f48b40b
fix bug where defect concentrations could not be found from min_max_X
alexsquires Aug 8, 2024
b8cf015
tests written and passing locally
alexsquires Aug 8, 2024
62f65e5
Merge `Doped/PyScFermi` backends to `FermiSolver`, docstring fleshing…
kavanase Aug 11, 2024
bdbdebb
Cleanup and formatting
kavanase Aug 13, 2024
b04b9bf
Update tutorial
kavanase Aug 13, 2024
12ee642
Remove `Parallel` code, add note, use `tqdm`, formatting and code eff…
kavanase Aug 15, 2024
ddea60f
Allow `bulk_dos` to be set in `DefectThermodynamics` init, or as prop…
kavanase Aug 15, 2024
f4436e1
Fix some errors, set default `(quenched_)temperature` to 300K, refact…
kavanase Aug 15, 2024
697b2b0
Update citation info
kavanase Aug 15, 2024
42e5af5
Update to use flexible `chempot`/`el_refs` input and handling as in `…
kavanase Aug 15, 2024
b37f46e
Add note to tutorial
kavanase Aug 15, 2024
9d3a7cc
Some tests updates
kavanase Aug 16, 2024
da06266
Merge branch 'refs/heads/develop' into dopey_fermi
kavanase Aug 16, 2024
47637d9
Minor formatting
kavanase Aug 16, 2024
9935e0f
Extend tests to `3.12`
kavanase Aug 16, 2024
e5128ec
Merge branch 'develop' into dopey_fermi
kavanase Aug 20, 2024
4595bc9
Merge branch 'develop' into dopey_fermi
kavanase Aug 21, 2024
3935e4f
Merge `develop`
kavanase Sep 12, 2024
bcdf31a
fix grid generator, add fixed defects kwarg for py-sc-fermi usage
alexsquires Sep 18, 2024
a9c0a0a
docstrings for
alexsquires Sep 19, 2024
7ac07e1
update tutorial
alexsquires Sep 19, 2024
6120732
make sure arguement is passed forward correctly
alexsquires Sep 19, 2024
d0cb875
add custom fixed_defects to tutorial
alexsquires Sep 19, 2024
1e0f503
add line scan for min_max_X in binaries
alexsquires Sep 20, 2024
e65a3b3
fix optional args in min_max_X
alexsquires Sep 20, 2024
cab409a
add fixed_defects to tutorial notebook
alexsquires Sep 20, 2024
069c6bb
merge fermisolver in thermodynamics and chemicalpotentialgrid into ch…
alexsquires Sep 26, 2024
976a16f
update tutorial
alexsquires Oct 2, 2024
3825f20
tests
alexsquires Oct 17, 2024
823fa1f
tests passing locally
alexsquires Oct 18, 2024
c3ca6c9
test chemical potential grid methods
alexsquires Oct 18, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/pip_install_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

matrix:
os: [ ubuntu-latest, macos-14 ]
python-version: [ '3.9', '3.10', '3.11', '3.12' ]
python-version: [ '3.9', '3.10', '3.11', '3.12' ] # 3.13 released in October 2024
exclude:
- os: macos-14
python-version: '3.9' # Exclude Python 3.9 on macOS, not supported for macOS-14 tests
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

matrix:
os: [ ubuntu-latest, macos-14 ]
python-version: [ '3.9', '3.10', '3.11', '3.12' ]
python-version: [ '3.9', '3.10', '3.11', '3.12' ] # 3.13 released in October 2024
exclude:
- os: macos-14
python-version: '3.9' # Exclude Python 3.9 on macOS, not supported for macOS-14 tests
Expand Down
2 changes: 1 addition & 1 deletion docs/Dev_ToDo.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
- Note in chempots tutorial that LaTeX table generator website can also be used with the `to_csv()` function to generate LaTeX tables for the competing phases.
- Quick-start tutorial suggested by Alex G
- Test chempot grid plotting tool.
- `dist_tol` should also group defects for the concentration etc functions, currently doesn't (e.g. `CdTe_thermo.get_equilibrium_concentrations(limit="Te-rich", per_charge=False, fermi_level=0.5)` and `CdTe_thermo.dist_tol=10; CdTe_thermo.get_equilibrium_concentrations(limit="Te-rich", per_charge=False, fermi_level=0.5)`, same output)
- `dist_tol` should also group defects for the concentration etc functions, both in `thermodynamics.py` and `fermi_solver.py`, currently doesn't (e.g. `CdTe_thermo.get_equilibrium_concentrations(limit="Te-rich", per_charge=False, fermi_level=0.5)` and `CdTe_thermo.dist_tol=10; CdTe_thermo.get_equilibrium_concentrations(limit="Te-rich", per_charge=False, fermi_level=0.5)`, same output)
- Plotting lines colour updates.
- Add example to chemical potentials / thermodynamics analysis tutorials of varying chemical potentials as a function of temperature/pressure (i.e. gas phases), using the `Spinney` functions detailed here (https://spinney.readthedocs.io/en/latest/tutorial/chemipots.html#including-temperature-and-pressure-effects-through-the-gas-phase-chemical-potentials) or possibly `DefAP` functions otherwise.
- Add note to chempots tutorial that if your bulk phase is lower energy than its version on the MP (e.g. distorted perovskite), then you should use this for your bulk competing phase calculation.
Expand Down
1 change: 1 addition & 0 deletions docs/Tutorials.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ tutorials:
thermodynamics_tutorial
chemical_potentials_tutorial
advanced_analysis_tutorial
fermisolver_tutorial
plotting_customisation_tutorial
GGA_workflow_tutorial
1 change: 1 addition & 0 deletions docs/fermisolver_tutorial.ipynb
139 changes: 139 additions & 0 deletions doped/chemical_potentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -3367,3 +3367,142 @@ def combine_extrinsic(first, second, extrinsic_species):
"limits": new_limits,
"limits_wrt_el_refs": new_limits_wrt_el_refs,
}


class ChemicalPotentialGrid:
"""
A class to represent a grid in chemical potential space and to perform
operations such as generating a grid within the convex hull of given
vertices (chemical potential limits).

This class provides methods for handling and manipulating chemical
potential data, including the creation of a grid that spans a specified
chemical potential space.
"""

def __init__(self, chempots: dict[str, Any]):
r"""
Initializes the ``ChemicalPotentialGrid`` with chemical potential data.

This constructor takes a dictionary of chemical potentials and sets up
the initial vertices of the grid.

Args:
chempots (dict):
Dictionary of chemical potentials for the grid. This can have
the form of ``{"limits": [{'limit': [chempot_dict]}], ...}``
(the format generated by ``doped``\'s chemical potential parsing
functions), or alternatively can be a dictionary of the form
``{'limit': [chempot_dict, ...]}`` (i.e. matching the format of
``chempots["limits_wrt_el_refs"]`` from the ``doped`` ``chempots``
dict) where the keys are the limit names (e.g. "Cd-CdTe", "Cd-rich"
etc) and the values are dictionaries of a single chemical potential
limit in the format: ``{element symbol: chemical potential}``.

If ``chempots`` in the ``doped`` format is supplied, then the
chemical potentials `with respect to the elemental reference
energies` will be used (i.e. ``chempots["limits_wrt_el_refs"]``)!
"""
unformatted_chempots_dict = chempots.get("limits_wrt_el_refs", chempots)
test_elt = Element("H")
formatted_chempots_dict = {
limit: {
f"μ_{k}" if test_elt.is_valid_symbol(k) else k: v
for (k, v) in unformatted_chempots_subdict.items()
}
for limit, unformatted_chempots_subdict in unformatted_chempots_dict.items()
}

self.vertices = pd.DataFrame.from_dict(formatted_chempots_dict, orient="index")

def get_grid(self, n_points: int = 100) -> pd.DataFrame:
"""
Generates a grid within the convex hull of the vertices and
interpolates the dependent variable values.

This method creates a grid of points that spans the chemical potential
space defined by the vertices. It ensures that the generated points lie
within the convex hull of the provided vertices and interpolates the
chemical potential values at these points.

Args:
n_points (int):
The number of points to generate along each axis of the grid.
Note that this may not always be the final number of points in the grid,
as points lying outside the convex hull are excluded.
Default is 100.

Returns:
pd.DataFrame:
A ``DataFrame`` containing the points within the convex hull,
along with their corresponding interpolated chemical potential values.
Each row represents a point in the grid with associated chemical
potential values.
"""
return self.grid_from_dataframe(self.vertices, n_points)

@staticmethod
def grid_from_dataframe(mu_dataframe: pd.DataFrame, n_points: int = 100) -> pd.DataFrame:
r"""
Generates a grid within the convex hull of the vertices.

This method creates a grid of points within the convex hull
defined by the input ``DataFrame``\.
It interpolates the values of chemical potentials over this
grid, ensuring that all generated points lie within the convex
hull of the given vertices.

Args:
mu_dataframe (pd.DataFrame):
A ``DataFrame`` containing the chemical potential data,
with the last column representing the dependent variable
and the preceding columns representing the independent
variables.
n_points (int):
The number of points to generate along each axis of the
grid. Note that this may not always be the final number
of points in the grid, as points lying outside the convex
hull are excluded. Defaults to 100.

Returns:
pd.DataFrame:
A ``DataFrame`` containing the points within the convex
hull along with their corresponding interpolated values of
the dependent variable. Each row represents a point in the
grid.
"""
dependent_variable = mu_dataframe.columns[-1]
dependent_var = mu_dataframe[dependent_variable].to_numpy()
independent_vars = mu_dataframe.drop(columns=dependent_variable)

n_dims = independent_vars.shape[1] # Get the number of independent variables (dimensions)

# Get the convex hull of the vertices
hull = ConvexHull(independent_vars.values)

# Create a dense grid that covers the entire range of the vertices
grid_ranges = [
np.linspace(independent_vars.iloc[:, i].min(), independent_vars.iloc[:, i].max(), n_points)
for i in range(n_dims)
]
grid = np.meshgrid(*grid_ranges, indexing="ij") # Create N-dimensional grid
grid_points = np.vstack([g.ravel() for g in grid]).T # Flatten the grid to points

# Delaunay triangulation to get points inside the convex hull
delaunay = Delaunay(hull.points[hull.vertices])
inside_hull = delaunay.find_simplex(grid_points) >= 0
points_inside = grid_points[inside_hull]

# Interpolate the values to get the dependent chemical potential
values_inside = griddata(independent_vars.values, dependent_var, points_inside, method="linear")

# Combine points with their corresponding interpolated values
grid_with_values = np.hstack((points_inside, values_inside.reshape(-1, 1)))

# Add vertices to the grid
grid_with_values = np.vstack((grid_with_values, mu_dataframe.to_numpy()))

return pd.DataFrame(
grid_with_values,
columns=[*list(independent_vars.columns), dependent_variable],
)
4 changes: 3 additions & 1 deletion doped/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,9 @@ def _no_chempots_warning(property="Formation energies (and concentrations)"):
)


def _get_dft_chempots(chempots, el_refs, limit):
def _get_dft_chempots(
chempots: Optional[dict], el_refs: Optional[dict] = None, limit: Optional[str] = None
):
"""
Parse the DFT chempots from the input chempots and limit.
"""
Expand Down
Loading
Loading