Skip to content

Commit

Permalink
Merge pull request #47 from QuantumChemist/fix_unit_tests
Browse files Browse the repository at this point in the history
More features, improving the unit tests and fixing related issues
  • Loading branch information
JaGeo authored May 7, 2024
2 parents a452338 + ccef825 commit 01180d2
Show file tree
Hide file tree
Showing 286 changed files with 630,698 additions and 564,586 deletions.
11 changes: 7 additions & 4 deletions autoplex/data/common/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from emmet.core.math import Matrix3D
from pymatgen.core import Structure


from atomate2.forcefields.jobs import (
ForceFieldRelaxMaker,
ForceFieldStaticMaker,
Expand Down Expand Up @@ -139,9 +140,11 @@ def make(
**relax_kwargs,
)
jobs.append(static_conv_jobs)
plots = plot_force_distribution(
cell_factor, static_conv_jobs.output, x_min, x_max, bin_width
)
jobs.append(plots)

plots = plot_force_distribution(cell_factor_sequence, x_min, x_max, bin_width)
jobs.append(plots)
return Flow(jobs) # , plots.output)

@job
Expand Down Expand Up @@ -183,7 +186,7 @@ def static_run_and_convert(
}
if self.static_energy_maker is None:
self.static_energy_maker = GAPRelaxMaker(
potential_param_file_name=potential_filename, # task_document_kwargs={'dir_name': os.getcwd()},
potential_param_file_name=potential_filename,
relax_cell=False,
relax_kwargs=relax_kwargs,
steps=1,
Expand All @@ -201,4 +204,4 @@ def static_run_and_convert(
)
jobs.append(conv_job)

return Response(replace=Flow(jobs))
return Response(replace=Flow(jobs), output=conv_job.output)
43 changes: 25 additions & 18 deletions autoplex/data/common/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
from emmet.core.math import Matrix3D
from pymatgen.core import Structure

import os
import pickle
from pathlib import Path

import matplotlib.pyplot as plt
import numpy as np
Expand Down Expand Up @@ -37,8 +39,8 @@ def convert_to_extxyz(job_output, pkl_file, config_type, factor):
string of factor to resize cell parameters.
"""
with open(pkl_file, "rb") as file:
traj_obj = pickle.load(file) # job_output.dir_name +
with open(Path(job_output.dir_name) / Path(pkl_file), "rb") as file:
traj_obj = pickle.load(file)
# ForceFieldTaskDocument.from_ase_compatible_result() has no attribute dir_name implemented
data = to_ase_trajectory(traj_obj=traj_obj)
data[-1].write("tmp.xyz")
Expand All @@ -55,10 +57,13 @@ def convert_to_extxyz(job_output, pkl_file, config_type, factor):
i.pbc = True
write("ref_" + factor + ".extxyz", file, append=True)

return os.getcwd()


@job
def plot_force_distribution(
cell_factor_sequence: list[float],
cell_factor: float,
path,
x_min: int = 0,
x_max: int = 5,
bin_width: float = 0.125,
Expand All @@ -68,8 +73,8 @@ def plot_force_distribution(
Parameters
----------
cell_factor_sequence: list[float]
list of factor to resize cell parameters.
cell_factor: float
factor to resize cell parameters.
x_min: int
minimum value for the plot x-axis.
x_max: int
Expand All @@ -82,19 +87,21 @@ def plot_force_distribution(
plt.ylabel("Count")
bins = np.arange(x_min, x_max + bin_width, bin_width)
plot_total = []
for cell_factor in cell_factor_sequence:
plot_data = []
with open("ref_" + str(cell_factor).replace(".", "") + ".extxyz") as file:
for line in file:
# Split the line into columns
columns = line.split()

# Check if the line has exactly 10 columns
if len(columns) == 10:
# Extract the last three columns
data = columns[-3:]
norm_data = np.linalg.norm(data, axis=-1)
plot_data.append(norm_data)

# TODO split data collection and plotting

plot_data = []
with open(path + "/ref_" + str(cell_factor).replace(".", "") + ".extxyz") as file:
for line in file:
# Split the line into columns
columns = line.split()

# Check if the line has exactly 10 columns
if len(columns) == 10:
# Extract the last three columns
data = columns[-3:]
norm_data = np.linalg.norm(data, axis=-1)
plot_data.append(norm_data)

plt.hist(plot_data, bins=bins, edgecolor="black")
plt.title(f"Data for factor {cell_factor}")
Expand Down
Loading

0 comments on commit 01180d2

Please sign in to comment.