def _determine_inversion(self, permlist): x = np.array(self.atom_positions).flatten() xi = -x exact = ExactMatchAtomicCluster(permlist=permlist, can_invert=False) for rot, invert in exact.standard_alignments(x, xi): if exact.check_match(x, xi, rot, invert): self.inversion = exact._last_checked_rotation return
def _determine_rotational_symmetry(self, permlist): x = np.array(self.atom_positions).flatten() exact = ExactMatchAtomicCluster(permlist=permlist, can_invert=False) for rot, invert in exact.standard_alignments(x, x): if exact.check_match(x, x, rot, invert): rot = exact._last_checked_rotation exists = False for rot2 in self.symmetries: if np.linalg.norm(rot2 - rot) < 1e-6: exists = True break if not exists: self.symmetries.append(rot)
def _determine_rotational_symmetry(self, permlist): x = np.array(self.atom_positions).flatten() exact = ExactMatchAtomicCluster(permlist=permlist, can_invert=False) for rot, invert in exact.standard_alignments(x, x): if exact.check_match(x, x, rot, invert): rot = exact._last_checked_rotation exists=False for rot2 in self.symmetries: if np.linalg.norm(rot2 - rot) < 1e-6: exists=True break if not exists: self.symmetries.append(rot)
def testlj75(): # pragma: no cover import numpy as np coords = np.genfromtxt("tests/coords.lj75.gmin") from pele.mindist import ExactMatchAtomicCluster permlist = [list(range(75))] match = ExactMatchAtomicCluster(permlist=permlist, can_invert=True) calculator = PointGroupOrderCluster(match) pgorder = calculator(coords) print(pgorder)
def test1(self): d = os.path.dirname(__file__) fname = os.path.join(d, "coords.lj75.gmin.xyz") xyz = read_xyz(open(fname, "r")) coords = xyz.coords.reshape(-1) print fname self.assertEqual(coords.size, 75 * 3) permlist = [range(75)] match = ExactMatchAtomicCluster(permlist=permlist, can_invert=True) calculator = PointGroupOrderCluster(match) pgorder = calculator(coords) # print pgorder self.assertEqual(pgorder, 20)
def test1(self): d = os.path.dirname(__file__) dbfname = os.path.join(d, "lj75_very_small_pathsample.sqlite") from pele.systems import LJCluster natoms = 75 system = LJCluster(natoms) db = system.create_database(dbfname, createdb=False) permlist = [range(natoms)] ts_min = list(db.minima()) + list(db.transition_states()) for m in ts_min: match = ExactMatchAtomicCluster(permlist=permlist, can_invert=True) calculator = PointGroupOrderCluster(match) pgorder = calculator(m.coords) self.assertEqual(pgorder, m.pgorder)
def test1(self): from pele.systems import LJCluster natoms = 13 system = LJCluster(natoms) db = system.create_database() bh = system.get_basinhopping(db) bh.setPrinting(ostream=None) while db.minima()[0].energy > -44.3: bh.run(10) m = db.minima()[0] permlist = [range(natoms)] match = ExactMatchAtomicCluster(permlist=permlist, can_invert=True) calculator = PointGroupOrderCluster(match) pgorder = calculator(m.coords) # print pgorder self.assertEqual(pgorder, 120)
def get_compare_exact(self, **kwargs): """this function quickly determines whether two clusters are identical given translational, rotational and permutational symmeties """ permlist = self.get_permlist() return ExactMatchAtomicCluster(permlist=permlist, **kwargs)
def get_compare_exact(self, **kwargs): permlist = self.get_permlist() return ExactMatchAtomicCluster(permlist=permlist, **kwargs)
class TestExactMatchAtomicCluster(unittest.TestCase): def setUp(self): self.natoms = 11 self.system = LJCluster(self.natoms) self.match = ExactMatchAtomicCluster( permlist=self.system.get_permlist(), can_invert=True) def rc(self): return self.system.get_random_configuration() def rtrans(self, x): vec3 = np.random.uniform(-1, 1, 3) self.match.transform.translate(x, vec3) def rrot(self, x): aa = rotations.random_aa() mx = rotations.aa2mx(aa) self.match.transform.rotate(x, mx) def invert(self, x): self.match.transform.invert(x) def rperm(self, x): perm = range(self.natoms) np.random.shuffle(perm) self.match.transform.permute(x, perm) def are_same_check(self, tform): x1 = self.rc() x2 = x1.copy() tform(x1) tform(x2) x1_bkup = x1.copy() x2_bkup = x2.copy() self.assertTrue(self.match(x1, x2)) self.assertTrue((x1 == x1_bkup).all()) self.assertTrue((x2 == x2_bkup).all()) # transform = self.match.find_transformation(x1, x2) # self.assertIsNotNone(transform, "the structures should compare exact") # self.assertTrue((x1==x1_bkup).all()) # self.assertTrue((x2==x2_bkup).all()) # x2_tformed = x2.copy() # self.match.apply_transformation(x2_tformed, transform) # self.assertAlmostEqual(np.linalg.norm(x1_bkup - x2_tformed), 0., 3) def find_transform_check(self, tform): x1 = self.rc() x2 = x1.copy() tform(x1) tform(x2) x1_bkup = x1.copy() x2_bkup = x2.copy() transform = self.match.find_transformation(x1, x2) # print "invert", transform.invert # print "translate", transform.translation # print "permute", transform.permutation # print "rotate", transform.rotation self.assertIsNotNone(transform, "the structures should compare exact") self.assertTrue((x1 == x1_bkup).all(), "the passed structures should not be modified") self.assertTrue((x2 == x2_bkup).all(), "the passed structures should not be modified") # check that transform is the transformation that turns x2 into x1 x2_tformed = x2.copy() self.match.apply_transformation(x2_tformed, transform) self.assertAlmostEqual(np.linalg.norm(x1_bkup - x2_tformed), 0., 3) def apply_checks(self, tform): self.are_same_check(tform) self.find_transform_check(tform) def test_translate(self): self.apply_checks(self.rtrans) def test_rotate(self): self.apply_checks(self.rrot) def test_permute(self): self.apply_checks(self.rperm) def test_invert(self): self.apply_checks(self.rperm) def fchain(self, flist): """return a function which applies all of the functions in flist to the input""" def function_chain(x): for f in reversed(flist): f(x) return function_chain def test_2(self): # run apply_checks() on all combinations of length 2 of the transformations flist_all = [self.invert, self.rrot, self.rtrans, self.rperm] for flist in itertools.product(flist_all, repeat=2): tform = self.fchain(flist) self.apply_checks(tform) def test_3(self): # run apply_checks() on all combinations of lenth 3 of the transformations flist_all = [self.invert, self.rrot, self.rtrans, self.rperm] for flist in itertools.product(flist_all, repeat=3): tform = self.fchain(flist) self.apply_checks(tform) def test_4(self): # run apply_checks() on all combinations of lenth 4 of the transformations flist_all = [self.invert, self.rrot, self.rtrans, self.rperm] for flist in itertools.product(flist_all, repeat=4): tform = self.fchain(flist) self.apply_checks(tform)
def setUp(self): self.natoms = 11 self.system = LJCluster(self.natoms) self.match = ExactMatchAtomicCluster( permlist=self.system.get_permlist(), can_invert=True)
def get_compare_exact(self, **kwargs): permlist = [range(self.natoms)] return ExactMatchAtomicCluster(permlist=permlist, **kwargs)
def setUp(self): self.natoms = 11 self.system = LJCluster(self.natoms) self.match = ExactMatchAtomicCluster(permlist=self.system.get_permlist(), can_invert=True)
class TestExactMatchAtomicCluster(unittest.TestCase): def setUp(self): self.natoms = 11 self.system = LJCluster(self.natoms) self.match = ExactMatchAtomicCluster(permlist=self.system.get_permlist(), can_invert=True) def rc(self): return self.system.get_random_configuration() def rtrans(self, x): vec3 = np.random.uniform(-1,1,3) self.match.transform.translate(x, vec3) def rrot(self, x): aa = rotations.random_aa() mx = rotations.aa2mx(aa) self.match.transform.rotate(x, mx) def invert(self, x): self.match.transform.invert(x) def rperm(self, x): perm = range(self.natoms) np.random.shuffle(perm) self.match.transform.permute(x, perm) def are_same_check(self, tform): x1 = self.rc() x2 = x1.copy() tform(x1) tform(x2) x1_bkup = x1.copy() x2_bkup = x2.copy() self.assertTrue(self.match(x1, x2)) self.assertTrue((x1==x1_bkup).all()) self.assertTrue((x2==x2_bkup).all()) # transform = self.match.find_transformation(x1, x2) # self.assertIsNotNone(transform, "the structures should compare exact") # self.assertTrue((x1==x1_bkup).all()) # self.assertTrue((x2==x2_bkup).all()) # x2_tformed = x2.copy() # self.match.apply_transformation(x2_tformed, transform) # self.assertAlmostEqual(np.linalg.norm(x1_bkup - x2_tformed), 0., 3) def find_transform_check(self, tform): x1 = self.rc() x2 = x1.copy() tform(x1) tform(x2) x1_bkup = x1.copy() x2_bkup = x2.copy() transform = self.match.find_transformation(x1, x2) # print "invert", transform.invert # print "translate", transform.translation # print "permute", transform.permutation # print "rotate", transform.rotation self.assertIsNotNone(transform, "the structures should compare exact") self.assertTrue((x1==x1_bkup).all(), "the passed structures should not be modified") self.assertTrue((x2==x2_bkup).all(), "the passed structures should not be modified") # check that transform is the transformation that turns x2 into x1 x2_tformed = x2.copy() self.match.apply_transformation(x2_tformed, transform) self.assertAlmostEqual(np.linalg.norm(x1_bkup - x2_tformed), 0., 3) def apply_checks(self, tform): self.are_same_check(tform) self.find_transform_check(tform) def test_translate(self): self.apply_checks(self.rtrans) def test_rotate(self): self.apply_checks(self.rrot) def test_permute(self): self.apply_checks(self.rperm) def test_invert(self): self.apply_checks(self.rperm) def fchain(self, flist): """return a function which applies all of the functions in flist to the input""" def function_chain(x): for f in reversed(flist): f(x) return function_chain def test_2(self): # run apply_checks() on all combinations of length 2 of the transformations flist_all = [self.invert, self.rrot, self.rtrans, self.rperm] for flist in itertools.product(flist_all, repeat=2): tform = self.fchain(flist) self.apply_checks(tform) def test_3(self): # run apply_checks() on all combinations of lenth 3 of the transformations flist_all = [self.invert, self.rrot, self.rtrans, self.rperm] for flist in itertools.product(flist_all, repeat=3): tform = self.fchain(flist) self.apply_checks(tform) def test_4(self): # run apply_checks() on all combinations of lenth 4 of the transformations flist_all = [self.invert, self.rrot, self.rtrans, self.rperm] for flist in itertools.product(flist_all, repeat=4): tform = self.fchain(flist) self.apply_checks(tform)