Skip to content

Commit

Permalink
update agents to compute filtered phase diagram, upgrade submission e…
Browse files Browse the repository at this point in the history
…rror handling
  • Loading branch information
JosephMontoya-TRI committed Jan 28, 2021
1 parent 0d6b30d commit c89cf94
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
23 changes: 19 additions & 4 deletions camd/agent/stability.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from qmpy.analysis.thermodynamics.phase import Phase, PhaseData
from camd.analysis import PhaseSpaceAL, ELEMENTS
from camd.agent.base import HypothesisAgent, QBC
from camd.utils.data import filter_dataframe_by_composition
from pymatgen import Composition

from sklearn.gaussian_process.kernels import RBF, ConstantKernel
from sklearn.gaussian_process import GaussianProcessRegressor
Expand Down Expand Up @@ -74,22 +76,34 @@ def __init__(
# These might be able to go into the base class
self.cv_score = np.nan

def get_pd(self):
def get_pd(self, chemsys=None):
"""
Refresh the phase diagram associated with the seed_data
Args:
chemsys (str): chemical system for which to filter
seed data to provide partial phase diagram
Returns:
None
"""
self.pd = PhaseData()
# Filter seed data by relevant chemsys
if chemsys:
total_comp = Composition(chemsys.replace('-', ''))
filtered = filter_dataframe_by_composition(
self.seed_data, total_comp)
else:
filtered = self.seed_data

phases = [
Phase(
row["Composition"],
energy=row["delta_e"],
per_atom=True,
description=row_index,
)
for row_index, row in self.seed_data.iterrows()
for row_index, row in filtered.iterrows()
]
phases.extend([Phase(el, 0.0, per_atom=True) for el in ELEMENTS])
self.pd.add_phases(phases)
Expand Down Expand Up @@ -174,8 +188,9 @@ def update_candidate_stabilities(self, formation_energies, sort=True, floor=-6.0
for m_id, data in self.candidate_data.iterrows()
]

# Refresh and copy seed PD
pd_ml = deepcopy(self.get_pd())
# Refresh and copy seed PD filtered by candidates
all_comp = self.candidate_data['Composition'].sum()
pd_ml = deepcopy(self.get_pd(all_comp))
pd_ml.add_phases(candidate_phases)
space_ml = PhaseSpaceAL(bounds=ELEMENTS, data=pd_ml)

Expand Down
27 changes: 16 additions & 11 deletions camd/experiment/dft.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ def submit_dft_calcs_to_mc1(self):
)

for structure_id, row in self.current_data.iterrows():
calc_path = os.path.join(parent_dir, structure_id, "_1")
# Replace structure id in path to avoid confusing mc1
calc_path = os.path.join(parent_dir, structure_id.replace('-', ''), "_1")
os.makedirs(calc_path)
with cd(calc_path):
# Write input cif file and python model file
Expand All @@ -237,21 +238,25 @@ def submit_dft_calcs_to_mc1(self):
"us-east-1",
]
)
response = response.decode("utf-8")
response = re.findall("({.+})", response, re.DOTALL)[0]
data = json.loads(response)
data.update(
{
"path": os.getcwd(),
"status": "SUBMITTED",
"start_time": datetime.utcnow(),
}
)
except subprocess.CalledProcessError as e:
print(e.output)
data = {"path": os.getcwd(),
"status": "FAILED",
"error": "failed submission {}".format(e.output)}

response = response.decode("utf-8")
response = re.findall("({.+})", response, re.DOTALL)[0]
data = json.loads(response)
data.update(
{
"path": os.getcwd(),
"status": "SUBMITTED",
"start_time": datetime.utcnow(),
}
)
update_dataframe_row(self.current_data, structure_id, data)


def check_dft_calcs(self):
"""
Helper function to check DFT calculations via polling
Expand Down

0 comments on commit c89cf94

Please sign in to comment.