-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #387 from pyiron/flattraj
Use FlattenedStorage in NeighborsTrajectory
- Loading branch information
Showing
3 changed files
with
96 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# coding: utf-8 | ||
# Copyright (c) Max-Planck-Institut für Eisenforschung GmbH - Computational Materials Design (CM) Department | ||
# Distributed under the terms of "New BSD License", see the LICENSE file. | ||
|
||
import unittest | ||
import numpy as np | ||
from pyiron_atomistics.atomistics.structure.neighbors import NeighborsTrajectory | ||
from pyiron_atomistics.atomistics.structure.structurestorage import StructureStorage | ||
from pyiron_atomistics.atomistics.structure.factory import StructureFactory | ||
|
||
class TestNeighborsTrajectory(unittest.TestCase): | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
cls.canonical = StructureStorage() | ||
cls.grandcanonical = StructureStorage() | ||
|
||
bulk = StructureFactory().bulk("Fe") | ||
for n in range(3): | ||
bulk.positions += np.random.normal(scale=.1, size=bulk.positions.shape) | ||
cls.canonical.add_structure(bulk) | ||
cls.grandcanonical.add_structure(bulk.repeat( (n+1, 1, 1) )) | ||
|
||
def test_canonical(self): | ||
traj = NeighborsTrajectory(has_structure=self.canonical) | ||
traj.compute_neighbors() | ||
self.assertEqual(traj.indices.shape, (3, 1, 12), | ||
"indices from trajectory have wrong shape.") | ||
self.assertEqual(traj.distances.shape, (3, 1, 12), | ||
"distances from trajectory have wrong shape.") | ||
self.assertEqual(traj.vecs.shape, (3, 1, 12, 3), | ||
"vecs from trajectory have wrong shape.") | ||
for i in range(3): | ||
neigh = self.canonical.get_structure(i).get_neighbors() | ||
self.assertTrue(np.array_equal(traj.indices[i], neigh.indices), | ||
"indices from trajectory and get_neighbors not equal") | ||
self.assertTrue(np.array_equal(traj.distances[i], neigh.distances), | ||
"distances from trajectory and get_neighbors not equal") | ||
self.assertTrue(np.array_equal(traj.vecs[i], neigh.vecs), | ||
"vecs from trajectory and get_neighbors not equal") | ||
|
||
def test_grandcanonical(self): | ||
traj = NeighborsTrajectory(has_structure=self.grandcanonical) | ||
traj.compute_neighbors() | ||
self.assertEqual(traj.indices.shape, (3, 3, 12), | ||
"indices from trajectory have wrong shape.") | ||
self.assertEqual(traj.distances.shape, (3, 3, 12), | ||
"distances from trajectory have wrong shape.") | ||
self.assertEqual(traj.vecs.shape, (3, 3, 12, 3), | ||
"vecs from trajectory have wrong shape.") | ||
for i in range(3): | ||
neigh = self.grandcanonical.get_structure(i).get_neighbors() | ||
self.assertTrue(np.array_equal(traj.indices[i][:i+1], neigh.indices), | ||
"indices from trajectory and get_neighbors not equal") | ||
self.assertTrue(np.array_equal(traj.distances[i][:i+1], neigh.distances), | ||
"distances from trajectory and get_neighbors not equal") | ||
self.assertTrue(np.array_equal(traj.vecs[i][:i+1], neigh.vecs), | ||
"vecs from trajectory and get_neighbors not equal") |