Skip to content

Commit

Permalink
pbc correctly handled when trasferring to json and back Issue #210 (#211
Browse files Browse the repository at this point in the history
)

* pbc correctly handled when trasferring to json and back

also fix ASEComputeBonds which previously modified atoms

also add .vscode to gitognore

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* store PBC key

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Fabian <46721498+PythonFZ@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 16, 2023
1 parent 61f3cde commit f1da870
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 38 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,4 @@ cython_debug/
.idea/

tmp/
.vscode
12 changes: 12 additions & 0 deletions tests/test_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pytest
from ase.build import bulk, molecule

from zndraw.data import atoms_from_json, atoms_to_json


@pytest.mark.parametrize(
"atoms", [(molecule("C6H6")), (molecule("H2O")), (bulk("Cu", "fcc", a=3.6))]
)
def test_atoms_from_and_to_json_return_unchanged_atoms_object(atoms):
atom_copy = atoms.copy()
assert atom_copy == atoms_from_json(atoms_to_json(atoms))
32 changes: 0 additions & 32 deletions tests/test_zndraw.py

This file was deleted.

9 changes: 5 additions & 4 deletions zndraw/bonds/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ def build_graph(self, atoms: ase.Atoms):
self.double_bond_multiplier,
self.triple_bond_multiplier,
]
connectivity_matrix = np.zeros((len(atoms), len(atoms)), dtype=int)
atoms.pbc = False
distance_matrix = atoms.get_all_distances(mic=False)
atoms_copy = atoms.copy()
connectivity_matrix = np.zeros((len(atoms_copy), len(atoms_copy)), dtype=int)
atoms_copy.pbc = False
distance_matrix = atoms_copy.get_all_distances(mic=False)
np.fill_diagonal(distance_matrix, np.inf)
for cutoff in cutoffs:
cutoffs = np.array(natural_cutoffs(atoms, mult=cutoff))
cutoffs = np.array(natural_cutoffs(atoms_copy, mult=cutoff))
cutoffs = cutoffs[:, None] + cutoffs[None, :]
connectivity_matrix[distance_matrix <= cutoffs] += 1
G = nx.from_numpy_array(connectivity_matrix)
Expand Down
2 changes: 1 addition & 1 deletion zndraw/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def atoms_from_json(data: dict) -> ase.Atoms:
atoms = ase.Atoms(
numbers=data["numbers"],
cell=data["cell"],
pbc=True,
pbc=data["pbc"],
positions=data["positions"],
)

Expand Down
13 changes: 12 additions & 1 deletion zndraw/static/pycom/Cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,24 @@ class Atom {
}

class Atoms {
constructor({ positions, cell, numbers, colors, radii, connectivity, calc }) {
constructor({
positions,
cell,
numbers,
colors,
radii,
connectivity,
calc,
pbc,
}) {
this.positions = positions;
this.cell = cell;
this.numbers = numbers;
this.colors = colors;
this.radii = radii;
this.connectivity = connectivity;
this.calc = calc;
this.pbc = pbc;

this.length = this.positions.length;
}
Expand Down Expand Up @@ -65,6 +75,7 @@ class Cache {
radii: data[key].radii,
connectivity: data[key].connectivity,
calc: data[key].calc,
pbc: data[key].pbc,
});
});
const slider = document.getElementById("frame-slider");
Expand Down

0 comments on commit f1da870

Please sign in to comment.