def test_to_from_file_string(self): for fmt in ["cif", "json", "poscar", "cssr"]: s = self.struct.to(fmt=fmt) self.assertIsNotNone(s) ss = IStructure.from_str(s, fmt=fmt) self.assertArrayAlmostEqual(ss.lattice.lengths_and_angles, self.struct.lattice.lengths_and_angles, decimal=5) self.assertArrayAlmostEqual(ss.frac_coords, self.struct.frac_coords) self.assertIsInstance(ss, IStructure) self.struct.to(filename="POSCAR.testing") self.assertTrue(os.path.exists("POSCAR.testing")) os.remove("POSCAR.testing") self.struct.to(filename="Si_testing.yaml") self.assertTrue(os.path.exists("Si_testing.yaml")) s = Structure.from_file("Si_testing.yaml") self.assertEqual(s, self.struct) os.remove("Si_testing.yaml") self.struct.to(filename="POSCAR.testing.gz") s = Structure.from_file("POSCAR.testing.gz") self.assertEqual(s, self.struct) os.remove("POSCAR.testing.gz")
def test_to_from_file_string(self): for fmt in ["cif", "json", "poscar", "cssr"]: s = self.struct.to(fmt=fmt) self.assertIsNotNone(s) ss = IStructure.from_str(s, fmt=fmt) self.assertArrayAlmostEqual( ss.lattice.lengths_and_angles, self.struct.lattice.lengths_and_angles, decimal=5) self.assertArrayAlmostEqual(ss.frac_coords, self.struct.frac_coords) self.assertIsInstance(ss, IStructure) self.struct.to(filename="POSCAR.testing") self.assertTrue(os.path.exists("POSCAR.testing")) os.remove("POSCAR.testing") self.struct.to(filename="Si_testing.yaml") self.assertTrue(os.path.exists("Si_testing.yaml")) s = Structure.from_file("Si_testing.yaml") self.assertEqual(s, self.struct) os.remove("Si_testing.yaml") self.struct.to(filename="POSCAR.testing.gz") s = Structure.from_file("POSCAR.testing.gz") self.assertEqual(s, self.struct) os.remove("POSCAR.testing.gz")
def load_jit_model(model_file, crystal_file_handle): model = torch.jit.load(model_file) model.eval() cif_str = crystal_file_handle.read().decode("utf-8") struct = IStructure.from_str(cif_str, fmt="cif") dataset = StructureOnlyDataset([struct]) dataloader = DataLoader(dataset, batch_size=1) input = next(iter(dataloader)) x, y = model(input) x = x.detach().numpy() y = y.detach().numpy() return x, y