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

include DataConatiner check #514

Merged
merged 3 commits into from
Feb 9, 2022
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
16 changes: 8 additions & 8 deletions pyiron_atomistics/atomistics/master/murnaghan.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@


def _debye_kernel(xi):
return xi ** 3 / (np.exp(xi) - 1)
return xi**3 / (np.exp(xi) - 1)


def debye_integral(x):
Expand All @@ -40,16 +40,16 @@ def debye_integral(x):

def debye_function(x):
if hasattr(x, "__len__"):
return np.array([3 / xx ** 3 * debye_integral(xx) for xx in x])
return 3 / x ** 3 * debye_integral(x)
return np.array([3 / xx**3 * debye_integral(xx) for xx in x])
return 3 / x**3 * debye_integral(x)


# https://gitlab.com/ase/ase/blob/master/ase/eos.py
def birchmurnaghan_energy(V, E0, B0, BP, V0):
"BirchMurnaghan equation from PRB 70, 224107"
eta = (V0 / V) ** (1 / 3)
return E0 + 9 * B0 * V0 / 16 * (eta ** 2 - 1) ** 2 * (
6 + BP * (eta ** 2 - 1) - 4 * eta ** 2
return E0 + 9 * B0 * V0 / 16 * (eta**2 - 1) ** 2 * (
6 + BP * (eta**2 - 1) - 4 * eta**2
)


Expand Down Expand Up @@ -88,7 +88,7 @@ def pouriertarantola(V, E0, B0, BP, V0):
eta = (V / V0) ** (1 / 3)
squiggle = -3 * np.log(eta)

E = E0 + B0 * V0 * squiggle ** 2 / 6 * (3 + squiggle * (BP - 2))
E = E0 + B0 * V0 * squiggle**2 / 6 * (3 + squiggle * (BP - 2))
return E


Expand Down Expand Up @@ -235,7 +235,7 @@ def debye_temperature(self):

GPaTokBar = 10
Ang3_to_Bohr3 = (
scipy.constants.angstrom ** 3
scipy.constants.angstrom**3
/ scipy.constants.physical_constants["Bohr radius"][0] ** 3
)
convert = 67.48 # conversion factor, Moruzzi Eq. (4)
Expand Down Expand Up @@ -505,7 +505,7 @@ def _fit_leastsq(self, volume_lst, energy_lst, fittype="birchmurnaghan"):
a, b, c = np.polyfit(vol_lst, eng_lst, 2)
v0 = -b / (2 * a)
pfit_leastsq, perr_leastsq = fit_leastsq(
[a * v0 ** 2 + b * v0 + c, 2 * a * v0 * eV_div_A3_to_GPa, 4, v0],
[a * v0**2 + b * v0 + c, 2 * a * v0 * eV_div_A3_to_GPa, 4, v0],
vol_lst,
eng_lst,
fittype,
Expand Down
2 changes: 1 addition & 1 deletion pyiron_atomistics/atomistics/master/phonopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def get_hesse_matrix(self):
unit_conversion = (
scipy.constants.physical_constants["Hartree energy in eV"][0]
/ scipy.constants.physical_constants["Bohr radius"][0] ** 2
* scipy.constants.angstrom ** 2
* scipy.constants.angstrom**2
)
force_shape = np.shape(self.phonopy.force_constants)
force_reshape = force_shape[0] * force_shape[2]
Expand Down
2 changes: 1 addition & 1 deletion pyiron_atomistics/atomistics/structure/atoms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1939,7 +1939,7 @@ def get_distance(self, a0, a1, mic=True, vector=False):
if mic:
distance, d_len = find_mic(distance, self.cell, self.pbc)
else:
d_len = np.array([np.sqrt((distance ** 2).sum())])
d_len = np.array([np.sqrt((distance**2).sum())])
if vector:
return distance[0]

Expand Down
4 changes: 2 additions & 2 deletions pyiron_atomistics/atomistics/structure/neighbors.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def _estimate_num_neighbors(
volume = self._ref_structure.get_volume(per_atom=True)
width_buffer = 1 + width_buffer
width_buffer *= get_volume_of_n_sphere_in_p_norm(3, self.norm_order)
num_neighbors = max(14, int(width_buffer * cutoff_radius ** 3 / volume))
num_neighbors = max(14, int(width_buffer * cutoff_radius**3 / volume))
elif num_neighbors is None:
num_neighbors = self.num_neighbors
if self.num_neighbors is None:
Expand Down Expand Up @@ -575,7 +575,7 @@ def centrosymmetry(self):
indices = np.indices((len(self.vecs),) + all_arr.shape[:-1])
v = self.vecs[indices[0], all_arr[np.newaxis, :, :, 0]]
v += self.vecs[indices[0], all_arr[np.newaxis, :, :, 1]]
return np.sum(v ** 2, axis=-1).sum(axis=-1).min(axis=-1)
return np.sum(v**2, axis=-1).sum(axis=-1).min(axis=-1)

def __getattr__(self, name):
"""Attributes for the mode. Same as setting `neigh.mode`."""
Expand Down
2 changes: 1 addition & 1 deletion pyiron_atomistics/atomistics/structure/sparse_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def to_hdf(self, hdf, key):
my_dict["index"] = self.keys()
if data_type == "list_bool":
my_dict["values"] = [
sum([2 ** i * int(v) for i, v in enumerate(val)])
sum([2**i * int(v) for i, v in enumerate(val)])
for val in self.values()
]
else:
Expand Down
2 changes: 1 addition & 1 deletion pyiron_atomistics/atomistics/volumetric/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def gauss_f(d, fwhm=0.529177):
"""
sigma = fwhm / (2 * np.sqrt(2 * np.log(2)))
d2 = d * d
return np.exp(-1 / (2 * sigma ** 2) * d2)
return np.exp(-1 / (2 * sigma**2) * d2)

@staticmethod
def dist_between_two_grid_points(
Expand Down
4 changes: 2 additions & 2 deletions pyiron_atomistics/dft/job/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,11 +494,11 @@ def get_density_of_states(self, sigma=0.1, shift_by_fermi_energy=True, grid=None
- grid[np.newaxis, np.newaxis, np.newaxis, :]
)
hist = (
np.exp(-((hist) ** 2) / (2 * sigma ** 2))
np.exp(-((hist) ** 2) / (2 * sigma**2))
* k_weights[np.newaxis, :, np.newaxis, np.newaxis]
)
hist = np.sum(hist, axis=(1, 2))
hist *= 2 / len(eigen_values) / np.sqrt(2 * np.pi * sigma ** 2)
hist *= 2 / len(eigen_values) / np.sqrt(2 * np.pi * sigma**2)
return {"grid": grid, "dos": hist}


Expand Down
17 changes: 10 additions & 7 deletions pyiron_atomistics/interactive/sxextoptint.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,16 @@ def _write_input(
selective_dynamics=False,
):
with open(os.path.join(working_directory, "optim.sx"), "w") as f:
content = "main { ricQN { ric { maxDist = %f; withAngles; } maxSteps = %i; dEnergy = %f; dF = %f; maxStepLength = %f; softModeDamping = %f;}}" % (
maxDist,
ionic_steps,
ionic_energy_tolerance,
ionic_force_tolerance,
max_step_length,
soft_mode_damping,
content = (
"main { ricQN { ric { maxDist = %f; withAngles; } maxSteps = %i; dEnergy = %f; dF = %f; maxStepLength = %f; softModeDamping = %f;}}"
% (
maxDist,
ionic_steps,
ionic_energy_tolerance,
ionic_force_tolerance,
max_step_length,
soft_mode_damping,
)
)
Comment on lines +167 to 177
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's not part of the change set, but this should really be constructed programmatically

content = Group({'main': {'ricQN': {'ric': {...}, 'maxSteps': ionic_steps, ...}})

if selective_dynamics:
content += "structure { include <structure.sx>; }"
Expand Down
2 changes: 1 addition & 1 deletion pyiron_atomistics/lammps/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ def interactive_stress_getter(self):
ss[:, ind].reshape(len(self.structure), 3, 3)
/ constants.eV
* constants.bar
* constants.angstrom ** 3
* constants.angstrom**3
)
if np.matrix.trace(self._prism.R) != 3:
ss = np.einsum("ij,njk->nik", self._prism.R, ss)
Expand Down
2 changes: 1 addition & 1 deletion pyiron_atomistics/lammps/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __init__(self, cell, pbc=(True, True, True), digits=10):
yhi = np.sin(gamma) * bn
xzp = np.cos(beta) * cn
yzp = (bn * cn * np.cos(alpha) - xyp * xzp) / yhi
zhi = np.sqrt(cn ** 2 - xzp ** 2 - yzp ** 2)
zhi = np.sqrt(cn**2 - xzp**2 - yzp**2)

# Set precision
self.car_prec = dec.Decimal("10.0") ** int(
Expand Down
8 changes: 6 additions & 2 deletions pyiron_atomistics/sphinx/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ def __getitem__(self, item):
result = super().__getitem__(tag)
else:
result = result[tag]
if hasattr(result, "list_nodes") and "TYPE" in result.list_nodes():
if (
isinstance(result, HasGroups)
and "NAME" in result.list_nodes()
and result["NAME"] == "DataContainer"
):
result = result.to_object()
except (ValueError, KeyError):
return None
Expand Down Expand Up @@ -2046,7 +2050,7 @@ def get_volume(self):
volume = re.findall("Omega:.*$", self.log_file, re.MULTILINE)
if len(volume) > 0:
volume = float(volume[0].split()[1])
volume *= BOHR_TO_ANGSTROM ** 3
volume *= BOHR_TO_ANGSTROM**3
else:
volume = 0
return np.array(self.n_steps * [volume])
Expand Down
22 changes: 11 additions & 11 deletions pyiron_atomistics/testing/randomatomistic.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ def _s_r(self):

def interactive_energy_pot_getter(self):
return self.input["epsilon"] * (
np.sum(self._s_r ** 12) - np.sum(self._s_r ** 6)
np.sum(self._s_r**12) - np.sum(self._s_r**6)
)

def interactive_energy_tot_getter(self):
Expand All @@ -477,12 +477,12 @@ def interactive_energy_tot_getter(self):
)

def interadtive_energy_kin_getter(self):
v = np.einsum("ni,n->", self._velocity ** 2, self.structure.get_masses()) / 2
v = np.einsum("ni,n->", self._velocity**2, self.structure.get_masses()) / 2
return (
(
v
* self._unit.angstrom ** 2
/ self._unit.second ** 2
* self._unit.angstrom**2
/ self._unit.second**2
/ 1e-30
* self._unit.amu
)
Expand All @@ -494,8 +494,8 @@ def interactive_forces_getter(self):
all_values = self.input["epsilon"] * np.einsum(
"ni,n,n->ni",
self.neigh.flattened.vecs,
1 / self.neigh.flattened.distances ** 2,
12 * self._s_r ** 12 - 6 * self._s_r ** 6,
1 / self.neigh.flattened.distances**2,
12 * self._s_r**12 - 6 * self._s_r**6,
)
forces = np.zeros_like(self.structure.positions)
np.add.at(forces, self.neigh.flattened.atom_numbers, all_values)
Expand All @@ -511,8 +511,8 @@ def interactive_pressures_getter(self):
"ni,nj,n,n->ij",
self.neigh.flattened.vecs,
self.neigh.flattened.vecs,
1 / self.neigh.flattened.distances ** 2,
12 * self._s_r ** 12 - 6 * self._s_r ** 6,
1 / self.neigh.flattened.distances**2,
12 * self._s_r**12 - 6 * self._s_r**6,
)
* self._unit.electron_volt
)
Expand All @@ -523,15 +523,15 @@ def interactive_pressures_getter(self):
self._velocity,
self.structure.get_masses(),
)
* self._unit.angstrom ** 2
/ self._unit.second ** 2
* self._unit.angstrom**2
/ self._unit.second**2
/ 1e-30
* self._unit.amu
)
return (
(pot_part + kin_part)
/ self.structure.get_volume()
/ self._unit.angstrom ** 3
/ self._unit.angstrom**3
).to(self._unit.pascal).magnitude / 1e9

def interactive_stress_getter(self):
Expand Down
13 changes: 5 additions & 8 deletions pyiron_atomistics/thermodynamics/hessian.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,11 @@ def interactive_pressures_getter(self):

def interactive_cells_setter(self, cell):
if np.sum(self._stiffness_tensor) != 0:
epsilon = (
np.einsum(
"ij,jk->ik",
self.structure.cell,
np.linalg.inv(self._reference_structure.cell),
)
- np.eye(3)
)
epsilon = np.einsum(
"ij,jk->ik",
self.structure.cell,
np.linalg.inv(self._reference_structure.cell),
) - np.eye(3)
epsilon = (epsilon + epsilon.T) * 0.5
epsilon = np.append(
epsilon.diagonal(), np.roll(epsilon, -1, axis=0).diagonal()
Expand Down