def test_fit(self): """ Take two known matched structures 1) Ensure match 2) Ensure match after translation and rotations 3) Ensure no-match after large site translation 4) Ensure match after site shuffling """ sm = StructureMatcher() self.assertTrue(sm.fit(self.struct_list[0], self.struct_list[1])) # Test rotational/translational invariance op = SymmOp.from_axis_angle_and_translation([0, 0, 1], 30, False, np.array([0.4, 0.7, 0.9])) editor = StructureEditor(self.struct_list[1]) editor.apply_operation(op) self.assertTrue(sm.fit(self.struct_list[0], editor.modified_structure)) #Test failure under large atomic translation editor.translate_sites([0], [.4, .4, .2], frac_coords=True) self.assertFalse(sm.fit(self.struct_list[0], editor.modified_structure)) editor.translate_sites([0], [-.4, -.4, -.2], frac_coords=True) # random.shuffle(editor._sites) self.assertTrue(sm.fit(self.struct_list[0], editor.modified_structure)) #Test FrameworkComporator sm2 = StructureMatcher(comparator=FrameworkComparator()) lfp = read_structure(os.path.join(test_dir, "LiFePO4.cif")) nfp = read_structure(os.path.join(test_dir, "NaFePO4.cif")) self.assertTrue(sm2.fit(lfp, nfp)) self.assertFalse(sm.fit(lfp, nfp)) #Test anonymous fit. self.assertEqual(sm.fit_anonymous(lfp, nfp), {Composition("Li"): Composition("Na")}) self.assertAlmostEqual(sm.get_minimax_rms_anonymous(lfp, nfp)[0], 0.096084154118549828) #Test partial occupancies. s1 = Structure([[3, 0, 0], [0, 3, 0], [0, 0, 3]], [{"Fe": 0.5}, {"Fe": 0.5}, {"Fe": 0.5}, {"Fe": 0.5}], [[0, 0, 0], [0.25, 0.25, 0.25], [0.5, 0.5, 0.5], [0.75, 0.75, 0.75]]) s2 = Structure([[3, 0, 0], [0, 3, 0], [0, 0, 3]], [{"Fe": 0.25}, {"Fe": 0.5}, {"Fe": 0.5}, {"Fe": 0.75}], [[0, 0, 0], [0.25, 0.25, 0.25], [0.5, 0.5, 0.5], [0.75, 0.75, 0.75]]) self.assertFalse(sm.fit(s1, s2)) self.assertFalse(sm.fit(s2, s1)) s2 = Structure([[3, 0, 0], [0, 3, 0], [0, 0, 3]], [{"Fe": 0.25}, {"Fe": 0.25}, {"Fe": 0.25}, {"Fe": 0.25}], [[0, 0, 0], [0.25, 0.25, 0.25], [0.5, 0.5, 0.5], [0.75, 0.75, 0.75]]) self.assertEqual(sm.fit_anonymous(s1, s2), {Composition("Fe0.5"): Composition("Fe0.25")}) self.assertAlmostEqual(sm.get_minimax_rms_anonymous(s1, s2)[0], 0)
def test_init(self): fitter = StructureFitter(self.b, self.a) self.assertTrue(fitter.mapping_op != None, "No fit found!") #Now to try with rotated structure op = SymmOp.from_axis_angle_and_translation([0, 0, 1], 30, False, np.array([0, 0, 1])) editor = StructureEditor(self.a) editor.apply_operation(op) fitter = StructureFitter(self.b, editor.modified_structure) self.assertTrue(fitter.mapping_op != None, "No fit found!") #test with a supercell mod = SupercellMaker(self.a, scaling_matrix=[[2, 0, 0], [0, 1, 0], [0, 0, 1]]) a_super = mod.modified_structure fitter = StructureFitter(self.b, a_super) self.assertTrue(fitter.mapping_op != None, "No fit found!") # Test with a structure with a translated point editor = StructureEditor(self.a) site = self.a[0] editor.delete_site(0) trans = np.random.randint(0, 1000, 3) editor.insert_site(0, site.species_and_occu, site.frac_coords + trans, False, False) fitter = StructureFitter(self.b, editor.modified_structure) self.assertTrue(fitter.mapping_op != None, "No fit found for translation {}!".format(trans)) parser = CifParser(os.path.join(test_dir, "FePO4a.cif")) a = parser.get_structures()[0] parser = CifParser(os.path.join(test_dir, "FePO4b.cif")) b = parser.get_structures()[0] fitter = StructureFitter(b, a) self.assertTrue(fitter.mapping_op != None, "No fit found!")
def apply_transformation(self, structure): editor = StructureEditor(structure) editor.apply_operation(self._symmop) return editor.modified_structure
def apply_operation(structure, symmop): editor = StructureEditor(structure) editor.apply_operation(symmop) return editor.modified_structure