Skip to content

Commit

Permalink
Merge pull request #88 from GENESIS-EFRC/dev
Browse files Browse the repository at this point in the history
Address several performance issues, add FREED data, support for metastable CPDs
  • Loading branch information
mattmcdermott authored Feb 11, 2022
2 parents 996fb8d + cf343f8 commit 0a34b8e
Show file tree
Hide file tree
Showing 24 changed files with 454 additions and 43,217 deletions.
4 changes: 2 additions & 2 deletions requirements-testing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pytest-cov==3.0.0
pycodestyle==2.8.0
pydocstyle==6.1.1
flake8==4.0.1
mypy==0.910
mypy==0.931
mypy-extensions==0.4.3
pylint==2.12.2
black==21.12b0
black==22.1.0
57 changes: 57 additions & 0 deletions scripts/generate_free_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""
This script generates the data/freed/compounds.json file by using the s4 package as an interface.
"""

import numpy as np
from pymatgen.core.composition import Composition
from collections import OrderedDict
import json
import gzip

from s4.thermo.exp.freed import ExpThermoDatabase


if __name__ == "__main__":
xp = ExpThermoDatabase()
temps = np.arange(300, 2100, 100)
data = {}

# Acquire data
for c in xp.compositions:
if c.is_element:
continue

formula, factor = c.get_integer_formula_and_factor()

if not data.get(formula):
data[formula] = dict()

phases = xp.compositions[c]

for t in temps:
energies = []
for p in phases:
if t > p.tmax:
continue
energies.append(p.dgf(t))

if not energies:
continue

final_energy = min(energies)
g = final_energy / factor

if data[formula].get(t):
data[formula][t].append(g)
else:
data[formula][t] = [g]

# Clean the data
cleaned_data = {}
for f, energy_dict in data.items():
cleaned_data[f] = {str(t): min(e) for t, e in energy_dict.items()}

# Write to file
cleaned_data = OrderedDict(sorted(cleaned_data.items()))
with gzip.open("compounds.json.gz", "wt", encoding="ascii") as zipfile:
json.dump(cleaned_data, zipfile)
8 changes: 5 additions & 3 deletions scripts/generate_janaf_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""

import os
import gzip
import json
from collections import OrderedDict
import pandas
Expand Down Expand Up @@ -74,6 +75,7 @@
formula, factor = Composition(f).get_integer_formula_and_factor()
all_data[formula] = {temp: g / factor for temp, g in zip(temps, dGf)}

all_data = OrderedDict(sorted(all_data.items()))
with open("compounds.json", "w") as f:
json.dump(all_data, f)
all_data = OrderedDict(sorted(all_data.items()))

with gzip.open("compounds.json.gz", "wt", encoding="ascii") as zipfile:
json.dump(all_data, zipfile)
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ ignore = D105,D2,D4
ignore_missing_imports = True

[pylint.MASTER]
ignored-modules=scipy
extension-pkg-whitelist=scipy
ignore-patterns=test_
disable=unsubscriptable-object,
invalid-name,
Expand Down
12 changes: 11 additions & 1 deletion src/rxn_network/costs/competitiveness.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def __init__(
use_minimize=False,
basic_enumerator_kwargs: Optional[Dict] = None,
minimize_enumerator_kwargs: Optional[Dict] = None,
quiet=True,
name: str = "c_score",
):
"""
Expand Down Expand Up @@ -70,6 +71,10 @@ def __init__(
if not self.minimize_enumerator_kwargs.get("calculators"):
self.minimize_enumerator_kwargs["calculators"] = calcs

if quiet:
self.basic_enumerator_kwargs["quiet"] = True
self.minimize_enumerator_kwargs["quiet"] = True

def calculate(self, rxn: ComputedReaction) -> float:
"""
Calculates the competitiveness score for a given reaction by enumerating
Expand Down Expand Up @@ -105,6 +110,8 @@ def get_competing_rxns(self, rxn: ComputedReaction) -> List[ComputedReaction]:
A list of competing reactions
"""
chemsys = rxn.chemical_system.split("-")

precursors = [r.reduced_formula for r in rxn.reactants]
open_elem = self.open_elem

Expand All @@ -116,6 +123,9 @@ def get_competing_rxns(self, rxn: ComputedReaction) -> List[ComputedReaction]:
if open_phases:
precursors = list(set(precursors) - set(open_phases))

entries = self.entries.filter_by_stability(0.0).get_subset_in_chemsys(chemsys)
entries.update(rxn.entries) # add back entries which may have been filtered out

enumerators = []
if self.use_basic:
kwargs = self.basic_enumerator_kwargs.copy()
Expand Down Expand Up @@ -143,7 +153,7 @@ def get_competing_rxns(self, rxn: ComputedReaction) -> List[ComputedReaction]:

rxns = set()
for e in enumerators:
rxns.update(e.enumerate(self.entries))
rxns.update(e.enumerate(entries))

if rxn in rxns:
rxns.remove(rxn)
Expand Down
1 change: 1 addition & 0 deletions src/rxn_network/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
cwd = Path(__file__).parent.resolve()

PATH_TO_BARIN = cwd / "barin"
PATH_TO_FREED = cwd / "freed"
PATH_TO_NIST = cwd / "nist"

G_ELEMS = loadfn(cwd / "elements.json")
Expand Down
Loading

0 comments on commit 0a34b8e

Please sign in to comment.