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

use pyiron-internal is_skewed #63

Merged
merged 5 commits into from
Feb 5, 2021
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
19 changes: 19 additions & 0 deletions pyiron_atomistics/atomistics/structure/atoms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1948,6 +1948,25 @@ def get_voronoi_volume(self):
return self._analyse.pyscal_voronoi_volume()
get_voronoi_volume.__doc__ = Analyse.pyscal_voronoi_volume.__doc__

def is_skewed(self, tolerance=1.0e-8):
Copy link
Contributor

Choose a reason for hiding this comment

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

This should work, but isn't it more straightforward to check the dot product between cell vectors? Your reasoning is documented though, so I don't mind too much.

Copy link
Member Author

Choose a reason for hiding this comment

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

Uh that's a good point. I don't have a strong opinion about it. The only one thing is that I want to insist on making tolerance a dimensionless value, in which case the computational cost is probably very much the same. If other people prefer dot product I can also change it.

"""
Check whether the simulation box is skewed/sheared. The algorithm compares the box volume
and the product of the box length in each direction. If these numbers do not match, the box
is considered to be skewed and the function returns True

Args:
tolerance (float): Relative tolerance above which the structure is considered as skewed

Returns:
(bool): Whether the box is skewed or not.
"""
volume = self.get_volume()
prod = np.linalg.norm(self.cell, axis=-1).prod()
if volume > 0:
if abs(volume-prod)/volume < tolerance:
return False
return True

def find_mic(self, v, vectors=True):
"""
Find vectors following minimum image convention (mic). In principle this
Expand Down
42 changes: 11 additions & 31 deletions pyiron_atomistics/lammps/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,33 +108,20 @@ def interactive_cells_setter(self, cell):
"Warning: setting upper trangular matrix might slow down the calculation"
)

is_skewed = self._prism.is_skewed()
is_scaled = self.structure._is_scaled
if is_scaled:
warnings.warn('set_relative() is deprecated as of 2020-02-26. It is not guaranteed from pyiron_atomistics vers. 0.3')
is_skewed = self._structure_current.is_skewed(tolerance=1.0e-8)
was_skewed = self._structure_previous.is_skewed(tolerance=1.0e-8)

if is_skewed and is_scaled:
self._interactive_lib_command(
"change_box all triclinic"
)
if is_skewed:
if not was_skewed:
self._interactive_lib_command(
"change_box all triclinic"
)
self._interactive_lib_command(
"change_box all x final 0 %f y final 0 %f z final 0 %f \
xy final %f xz final %f yz final %f remap units box"
% (lx, ly, lz, xy, xz, yz)
)
elif is_skewed and not is_scaled:
self._interactive_lib_command(
"change_box all triclinic"
)
self._interactive_lib_command(
"change_box all x final 0 %f y final 0 %f z final 0 %f \
xy final %f xz final %f yz final %f units box"
% (lx, ly, lz, xy, xz, yz)
)
elif not is_skewed and is_scaled:
self._interactive_lib_command(
"change_box all triclinic"
)
elif was_skewed:
self._interactive_lib_command(
samwaseda marked this conversation as resolved.
Show resolved Hide resolved
"change_box all x final 0 %f y final 0 %f z final 0 %f \
xy final %f xz final %f yz final %f remap units box"
Expand All @@ -143,17 +130,10 @@ def interactive_cells_setter(self, cell):
self._interactive_lib_command(
"change_box all ortho"
)
else: # is neither skewed nor scaled
self._interactive_lib_command(
"change_box all triclinic"
)
self._interactive_lib_command(
"change_box all x final 0 %f y final 0 %f z final 0 %f \
xy final %f xz final %f yz final %f units box"
% (lx, ly, lz, 0.0, 0.0, 0.0)
)
else:
self._interactive_lib_command(
"change_box all ortho"
"change_box all x final 0 %f y final 0 %f z final 0 %f remap units box"
% (lx, ly, lz)
)

def interactive_volume_getter(self):
Expand Down
14 changes: 14 additions & 0 deletions tests/atomistics/structure/test_atoms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1607,6 +1607,20 @@ def test_get_wrapped_coordinates(self):
np.linalg.norm(position-structure.cell*0.1), 0
)

def test_is_skewed(self):
samwaseda marked this conversation as resolved.
Show resolved Hide resolved
structure = CrystalStructure("Fe", bravais_basis="bcc", lattice_constant=4.2, pbc=True)
self.assertFalse(
structure.is_skewed(), "is_skewed() returned True, while structure is not skewed"
)
structure.cell[0,0] += 0.01
self.assertFalse(
structure.is_skewed(), "is_skewed() returned True, while structure is not skewed"
)
structure.cell[1,0] += 0.01
self.assertTrue(
structure.is_skewed(), "is_skewed() returned False, while structure is skewed"
)

@staticmethod
def test_set_dihedral():
structure = ase_to_pyiron(molecule('H2COH'))
Expand Down
25 changes: 18 additions & 7 deletions tests/lammps/test_interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,30 @@ def tearDownClass(cls):
project.remove(enable=True)

def test_interactive_cells_setter(self):
self.job.interactive_cells_setter(np.eye(3))
atoms = Atoms("Fe8", positions=np.zeros((8, 3)), cell=np.eye(3), pbc=True)
self.job._structure_previous = atoms.copy()
self.job._structure_current = atoms.copy()
self.job.interactive_cells_setter(self.job._structure_current.cell)
self.assertEqual(
self.job._interactive_library._command[-3],
"change_box all triclinic",
)
self.assertEqual(
self.job._interactive_library._command[-2],
"change_box all x final 0 1.000000 y final 0 1.000000 z final 0 1.000000 xy final 0.000000 xz final 0.000000 yz final 0.000000 units box",
self.job._interactive_library._command[-1],
"change_box all x final 0 1.000000 y final 0 1.000000 z final 0 1.000000 remap units box",
)
self.job._structure_previous = atoms.copy()
self.job._structure_current = atoms.copy()
self.job._structure_previous.cell[1,0] += 0.01
self.job.interactive_cells_setter(self.job._structure_current.cell)
self.assertEqual(
self.job._interactive_library._command[-1],
"change_box all ortho",
)
self.job._structure_previous = atoms.copy()
self.job._structure_current = atoms.copy()
self.job._structure_current.cell[1,0] += 0.01
self.job.interactive_cells_setter(self.job._structure_current.cell)
self.assertEqual(
self.job._interactive_library._command[-2],
"change_box all triclinic",
)

def test_interactive_positions_setter(self):
self.job.interactive_positions_setter(np.arange(6).reshape(2, 3))
Expand Down