def test_get_structure_components(self): # test components are returned correctly with the right keys components = get_structure_components(self.tricky_structure) self.assertEqual(len(components), 1) self.assertEqual(components[0]['dimensionality'], 3) self.assertTrue(isinstance(components[0]['structure'], Structure)) self.assertEqual(components[0]['structure'].num_sites, 10) # test 2D structure and get orientation information components = get_structure_components(self.graphite, inc_orientation=True) self.assertEqual(len(components), 2) self.assertEqual(components[0]['dimensionality'], 2) self.assertTrue(isinstance(components[0]['structure'], Structure)) self.assertEqual(components[0]['structure'].num_sites, 2) self.assertEqual(components[0]['orientation'], (0, 0, 1))
def test_get_vdw_heterostructure_information(self): data = get_vdw_heterostructure_information( self.vdw_hetero_components, inc_ordered_components=True, inc_intercalants=True, ) self.assertEqual(len(data["ordered_components"]), 4) self.assertAlmostEqual( data["ordered_components"][0] ["structure_graph"].structure.frac_coords[0][0], 0.33330876, ) self.assertAlmostEqual( data["ordered_components"][3] ["structure_graph"].structure.frac_coords[0][0], 0.6666924, ) self.assertEqual(data["repeating_unit"], ["MoS2", "WS2"]) self.assertEqual(data["num_repetitions"], 2) self.assertEqual(data["intercalants"], []) # test error catching self.assertRaises(ValueError, get_vdw_heterostructure_information, self.mapi_components) self.assertRaises( KeyError, get_vdw_heterostructure_information, get_structure_components(self.vdw_hetero), )
def setUp(self): cnn = CrystalNN() self.mapi = cnn.get_bonded_structure(self.get_structure("mapi")) self.mapi_components = get_structure_components( self.mapi, inc_molecule_graph=True, inc_site_ids=True, inc_orientation=True) self.vdw_hetero = cnn.get_bonded_structure(self.get_structure("MoWS4")) self.vdw_hetero_components = get_structure_components( self.vdw_hetero, inc_molecule_graph=True, inc_site_ids=True, inc_orientation=True, )
def setUp(self): cnn = CrystalNN() mapi = cnn.get_bonded_structure(self.get_structure("mapi")) mapi_components = get_structure_components(mapi, inc_molecule_graph=True) mol_components, _ = filter_molecular_components(mapi_components) self.methylammonium = mol_components[0]['molecule_graph']
def test_get_formula_from_components(self): formula = get_formula_from_components(self.mapi_components, use_common_formulas=True, use_iupac_formula=True) self.assertTrue(formula, "CH3NH3PbI3") # check not using common formulas formula = get_formula_from_components(self.mapi_components, use_common_formulas=False, use_iupac_formula=True) self.assertTrue(formula, "CNH6PbI3") # check non-iupac ordering works formula = get_formula_from_components(self.mapi_components, use_iupac_formula=False, use_common_formulas=False) self.assertEqual(formula, "H6CNPbI3") # test multiple groups of different numbers of compositions s = CrystalNN().get_bonded_structure(self.get_structure("CuH8CN5Cl3")) comps = get_structure_components(s) formula = get_formula_from_components(comps, use_iupac_formula=True, use_common_formulas=True) self.assertEqual(formula, "(CuCN4HCl)2(NH2)2(H2)3(HCl)4") # test putting molecules first s = CrystalNN().get_bonded_structure( self.get_structure("ZrCuH8C2NCl6")) comps = get_structure_components(s) formula = get_formula_from_components( comps, molecules_first=False, use_iupac_formula=True, use_common_formulas=True, ) self.assertEqual(formula, "ZrCuCl6(CH3)2NH2") formula = get_formula_from_components( comps, molecules_first=True, use_iupac_formula=True, use_common_formulas=True, ) self.assertEqual(formula, "(CH3)2NH2ZrCuCl6")
def test_get_structure_components(self): # test components are returned correctly with the right keys components = get_structure_components(self.tricky_structure) self.assertEqual(len(components), 1) self.assertEqual(components[0]["dimensionality"], 3) self.assertTrue(isinstance(components[0]["structure_graph"], StructureGraph)) self.assertEqual(components[0]["structure_graph"].structure.num_sites, 10) # test 2D structure and get orientation information components = get_structure_components(self.graphite, inc_orientation=True) self.assertEqual(len(components), 2) self.assertEqual(components[0]["dimensionality"], 2) self.assertTrue(isinstance(components[0]["structure_graph"], StructureGraph)) self.assertEqual(components[0]["structure_graph"].structure.num_sites, 2) self.assertEqual(components[0]["orientation"], (0, 0, 1)) # test getting component graphs self.assertEqual(list(components[0]["structure_graph"].graph.nodes()), [0, 1])
def test_get_structure_components(self): # test components are returned correctly with the right keys components = get_structure_components(self.tricky_structure) self.assertEqual(len(components), 1) self.assertEqual(components[0]['dimensionality'], 3) self.assertTrue( isinstance(components[0]['structure_graph'], StructureGraph)) self.assertEqual(components[0]['structure_graph'].structure.num_sites, 10) # test 2D structure and get orientation information components = get_structure_components( self.graphite, inc_orientation=True) self.assertEqual(len(components), 2) self.assertEqual(components[0]['dimensionality'], 2) self.assertTrue( isinstance(components[0]['structure_graph'], StructureGraph)) self.assertEqual(components[0]['structure_graph'].structure.num_sites, 2) self.assertEqual(components[0]['orientation'], (0, 0, 1)) # test getting component graphs self.assertEqual(list(components[0]['structure_graph'].graph.nodes()), [0, 1])
def condense_structure(self, structure: Structure) -> Dict[str, Any]: """Condenses the structure into an intermediate dict representation. Args: structure: A pymatgen structure object. Returns: The condensed structure information. The data is formatted as a :obj:`dict` with a fixed set of keys. An up-to-date example of the, the condensed representation of MoS2 given in the documentation. See: ``robocrystallographer/docs_rst/source/format.rst`` or https://hackingmaterials.lbl.gov/robocrystallographer/format.html """ # sort so we can give proper symmetry labels structure = structure.get_sorted_structure() # wrap all site coords into unit cell structure.translate_sites(range(structure.num_sites), [1, 1, 1]) sga = SpacegroupAnalyzer(structure, symprec=self.symprec) if self.use_conventional_cell: structure = sga.get_conventional_standard_structure() else: structure = sga.get_symmetrized_structure() bonded_structure = self.near_neighbors.get_bonded_structure(structure) components = get_structure_components( bonded_structure, inc_orientation=True, inc_site_ids=True, inc_molecule_graph=True, ) dimensionality = max(c["dimensionality"] for c in components) mineral = self._condense_mineral(structure, components) formula = self._condense_formula(structure, components) structure_data = { "formula": formula, "spg_symbol": sga.get_space_group_symbol(), "crystal_system": sga.get_crystal_system(), "mineral": mineral, "dimensionality": dimensionality, } site_analyzer = SiteAnalyzer( bonded_structure, symprec=self.symprec, use_symmetry_equivalent_sites=self.use_symmetry_equivalent_sites, ) structure_data["sites"] = site_analyzer.get_all_site_summaries() structure_data[ "distances"] = site_analyzer.get_all_bond_distance_summaries() structure_data[ "angles"] = site_analyzer.get_all_connectivity_angle_summaries() structure_data[ "nnn_distances"] = site_analyzer.get_all_nnn_distance_summaries() component_summary, component_makeup = self._condense_components( components, sga, site_analyzer) structure_data["components"] = component_summary structure_data["component_makeup"] = component_makeup if components_are_vdw_heterostructure(components): hs_info = get_vdw_heterostructure_information( components, use_iupac_formula=self.use_iupac_formula, use_common_formulas=self.use_common_formulas, ) else: hs_info = None structure_data["vdw_heterostructure_info"] = hs_info return structure_data