Skip to content

Commit

Permalink
Merge pull request #506 from ACEsuit/develop
Browse files Browse the repository at this point in the history
correct pbc extension
  • Loading branch information
ilyes319 authored Jul 8, 2024
2 parents 6671b54 + 25e3596 commit 299385b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
9 changes: 5 additions & 4 deletions mace/data/neighborhood.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,18 @@ def get_neighborhood(
max_positions = np.max(np.absolute(positions)) + 1
# Extend cell in non-periodic directions
# For models with more than 5 layers, the multiplicative constant needs to be increased.
temp_cell = np.copy(cell)
if not pbc_x:
cell[:, 0] = max_positions * 5 * cutoff * identity[:, 0]
temp_cell[0, :] = max_positions * 5 * cutoff * identity[0, :]
if not pbc_y:
cell[:, 1] = max_positions * 5 * cutoff * identity[:, 1]
temp_cell[1, :] = max_positions * 5 * cutoff * identity[1, :]
if not pbc_z:
cell[:, 2] = max_positions * 5 * cutoff * identity[:, 2]
temp_cell[2, :] = max_positions * 5 * cutoff * identity[2, :]

sender, receiver, unit_shifts = neighbour_list(
quantities="ijS",
pbc=pbc,
cell=cell,
cell=temp_cell,
positions=positions,
cutoff=cutoff,
# self_interaction=True, # we want edges from atom to itself in different periodic images
Expand Down
14 changes: 7 additions & 7 deletions mace/data/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,20 +242,20 @@ def load_from_xyz(
atoms_without_iso_atoms = []

for idx, atoms in enumerate(atoms_list):
isolated_atom_config = len(atoms) == 1 and atoms.info.get("config_type") == "IsolatedAtom"
isolated_atom_config = (
len(atoms) == 1 and atoms.info.get("config_type") == "IsolatedAtom"
)
if isolated_atom_config:
if energy_key in atoms.info.keys():
atomic_energies_dict[atoms.get_atomic_numbers()[0]] = (
atoms.info[energy_key]
)
atomic_energies_dict[atoms.get_atomic_numbers()[0]] = atoms.info[
energy_key
]
else:
logging.warning(
f"Configuration '{idx}' is marked as 'IsolatedAtom' "
"but does not contain an energy. Zero energy will be used."
)
atomic_energies_dict[atoms.get_atomic_numbers()[0]] = np.zeros(
1
)
atomic_energies_dict[atoms.get_atomic_numbers()[0]] = np.zeros(1)
else:
atoms_without_iso_atoms.append(atoms)

Expand Down
7 changes: 2 additions & 5 deletions mace/modules/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,9 @@ def compute_forces_virials(
stress = torch.zeros_like(displacement)
if compute_stress and virials is not None:
cell = cell.view(-1, 3, 3)
volume = torch.einsum(
"zi,zi->z",
cell[:, 0, :],
torch.cross(cell[:, 1, :], cell[:, 2, :], dim=1),
).unsqueeze(-1)
volume = torch.linalg.det(cell).abs().unsqueeze(-1)
stress = virials / volume.view(-1, 1, 1)
stress = torch.where(torch.abs(stress) < 1e10, stress, torch.zeros_like(stress))
if forces is None:
forces = torch.zeros_like(positions)
if virials is None:
Expand Down

0 comments on commit 299385b

Please sign in to comment.