def figure_fractions(self, weights_options, morphing_factors=None): if morphing_factors is None: morphing_factors = np.linspace(1.0, 2.0, 21) # Set up the local geometry finder lgf = LocalGeometryFinder() lgf.setup_parameters(structure_refinement=lgf.STRUCTURE_REFINEMENT_NONE) # Set up the weights for the MultiWeights strategy weights = self.get_weights(weights_options) # Set up the strategy strat = MultiWeightsChemenvStrategy(dist_ang_area_weight=weights['DistAngArea'], self_csm_weight=weights['SelfCSM'], delta_csm_weight=weights['DeltaCSM'], cn_bias_weight=weights['CNBias'], angle_weight=weights['Angle'], normalized_angle_distance_weight=weights['NormalizedAngDist']) fake_valences = [-1] * (self.coordination_geometry.coordination_number + 1) fake_valences[0] = 1 fractions_initial_environment = np.zeros_like(morphing_factors) fractions_final_environment = np.zeros_like(morphing_factors) for ii, morphing_factor in enumerate(morphing_factors): print(ii) struct = self.get_structure(morphing_factor=morphing_factor) print(struct) # Get the StructureEnvironments lgf.setup_structure(structure=struct) se = lgf.compute_structure_environments(only_indices=[0], valences=fake_valences) strat.set_structure_environments(structure_environments=se) result = strat.get_site_coordination_environments_fractions(site=se.structure[0], isite=0, return_strategy_dict_info=True, return_all=True) for res in result: if res['ce_symbol'] == self.initial_environment_symbol: fractions_initial_environment[ii] = res['ce_fraction'] elif res['ce_symbol'] == self.expected_final_environment_symbol: fractions_final_environment[ii] = res['ce_fraction'] fig_width_cm = 8.25 fig_height_cm = 7.0 fig_width = fig_width_cm / 2.54 fig_height = fig_height_cm / 2.54 fig = plt.figure(num=1, figsize=(fig_width, fig_height)) subplot = fig.add_subplot(111) subplot.plot(morphing_factors, fractions_initial_environment, 'b-', label='{}'.format(self.initial_environment_symbol), linewidth=1.5) subplot.plot(morphing_factors, fractions_final_environment, 'g--', label='{}'.format(self.expected_final_environment_symbol), linewidth=1.5) plt.legend(fontsize=8.0, loc=7) plt.show()
def analyse_local_coord_env(atoms=None, ): """ """ #| - analyse_local_coord_env out_dict = dict() Ir_indices = [] for i, s in enumerate(atoms.get_chemical_symbols()): if s == "Ir": Ir_indices.append(i) struct = AseAtomsAdaptor.get_structure(atoms) lgf = LocalGeometryFinder() lgf.setup_structure(structure=struct) se = lgf.compute_structure_environments(maximum_distance_factor=1.41, only_cations=False) strategy = MultiWeightsChemenvStrategy.stats_article_weights_parameters() lse = LightStructureEnvironments.from_structure_environments( strategy=strategy, structure_environments=se) isite = 0 cor_env = [] coor_env_dict = dict() for isite in Ir_indices: c_env = lse.coordination_environments[isite] coor_env_dict[isite] = c_env cor_env += [c_env[0]['ce_symbol']] out_dict["coor_env_dict"] = coor_env_dict return (out_dict)
def get_cesym(lgf, structure, site): """See module docstring.""" # doc: http://pymatgen.org/_modules/pymatgen/analysis/chemenv/ # coordination_environments/coordination_geometry_finder.html lgf.setup_structure(structure) # doc: http://pymatgen.org/_modules/pymatgen/analysis/chemenv/ # coordination_environments/ # chemenv_strategies.html#MultiWeightsChemenvStrategy. # stats_article_weights_parameters strategy = MultiWeightsChemenvStrategy.stats_article_weights_parameters() # returns all information about the structure; se is a structure object se = lgf.compute_structure_environments(maximum_distance_factor=1.2, only_cations=False, only_indices=[site]) lse = LightStructureEnvironments.\ from_structure_environments(strategy=strategy, structure_environments=se) coor = lse.coordination_environments # ce = chemical environment # csm = continuous symmetry measure # from Waroquiers et al (verbatim) # DOI: 10.1021/acs.chemmater.7b02766 # "The environment of the atom is then the model polyhedron for which # the similarity is the highest, that is, for which the CSM is the lowest." # in this case, it looks like O:6 (octahedral?) return [coor[site][0]['ce_symbol'], coor[site][0]['csm']]
def setUp(self): with open("mp-7000.json", "r") as f: dict_lse = json.load(f) lse = LightStructureEnvironments.from_dict(dict_lse) struct = lse.structure bva = BVAnalyzer() valences = bva.get_valences(structure=struct) lgf = LocalGeometryFinder() lgf.setup_structure(structure=struct) se = lgf.compute_structure_environments(maximum_distance_factor=1.41, only_cations=False, valences=valences) strategy = MultiWeightsChemenvStrategy.stats_article_weights_parameters() self.lse = LightStructureEnvironments.from_structure_environments(strategy=strategy, structure_environments=se) with open("mp-5634.json", "r") as f: dict_lse2 = json.load(f) self.lse2 = LightStructureEnvironments.from_dict(dict_lse2)
def getMultiWeightsChemenvStrategy(struct): # Setup the local geometry finder lgf = LocalGeometryFinder() lgf.setup_parameters(centering_type='centroid', include_central_site_in_centroid=True) #you can also save the logging to a file, just remove the comment # logging.basicConfig(#filename='chemenv_structure_environments.log', # format='%(levelname)s:%(module)s:%(funcName)s:%(message)s', # level=logging.DEBUG) lgf.setup_structure(structure=struct) se = lgf.compute_structure_environments(maximum_distance_factor=1.41, only_cations=False) strategy = MultiWeightsChemenvStrategy.stats_article_weights_parameters() lse = LightStructureEnvironments.from_structure_environments( strategy=strategy, structure_environments=se) return lse.coordination_environments
def from_preset(preset): """ Use a standard collection of CE types and choose your ChemEnv neighbor-finding strategy. Args: preset (str): preset types ("simple" or "multi_weights"). Returns: ChemEnvSiteFingerprint object from a preset. """ cetypes = [ 'S:1', 'L:2', 'A:2', 'TL:3', 'TY:3', 'TS:3', 'T:4', 'S:4', 'SY:4', 'SS:4', 'PP:5', 'S:5', 'T:5', 'O:6', 'T:6', 'PP:6', 'PB:7', 'ST:7', 'ET:7', 'FO:7', 'C:8', 'SA:8', 'SBT:8', 'TBT:8', 'DD:8', 'DDPN:8', 'HB:8', 'BO_1:8', 'BO_2:8', 'BO_3:8', 'TC:9', 'TT_1:9', 'TT_2:9', 'TT_3:9', 'HD:9', 'TI:9', 'SMA:9', 'SS:9', 'TO_1:9', 'TO_2:9', 'TO_3:9', 'PP:10', 'PA:10', 'SBSA:10', 'MI:10', 'S:10', 'H:10', 'BS_1:10', 'BS_2:10', 'TBSA:10', 'PCPA:11', 'H:11', 'SH:11', 'CO:11', 'DI:11', 'I:12', 'PBP:12', 'TT:12', 'C:12', 'AC:12', 'SC:12', 'S:12', 'HP:12', 'HA:12', 'SH:13', 'DD:20' ] lgf = LocalGeometryFinder() lgf.setup_parameters( centering_type='centroid', include_central_site_in_centroid=True, structure_refinement=lgf.STRUCTURE_REFINEMENT_NONE) if preset == "simple": return ChemEnvSiteFingerprint( cetypes, SimplestChemenvStrategy(distance_cutoff=1.4, angle_cutoff=0.3), lgf) elif preset == "multi_weights": return ChemEnvSiteFingerprint( cetypes, MultiWeightsChemenvStrategy.stats_article_weights_parameters(), lgf) else: raise RuntimeError('unknown neighbor-finding strategy preset.')
def test_strategies(self): simplest_strategy_1 = SimplestChemenvStrategy() simplest_strategy_2 = SimplestChemenvStrategy(distance_cutoff=1.5, angle_cutoff=0.5) self.assertFalse(simplest_strategy_1 == simplest_strategy_2) simplest_strategy_1_from_dict = SimplestChemenvStrategy.from_dict( simplest_strategy_1.as_dict()) self.assertTrue(simplest_strategy_1, simplest_strategy_1_from_dict) effective_csm_estimator = { "function": "power2_inverse_decreasing", "options": { "max_csm": 8.0 }, } self_csm_weight = SelfCSMNbSetWeight() surface_definition = { "type": "standard_elliptic", "distance_bounds": { "lower": 1.1, "upper": 1.9 }, "angle_bounds": { "lower": 0.1, "upper": 0.9 }, } surface_definition_2 = { "type": "standard_elliptic", "distance_bounds": { "lower": 1.1, "upper": 1.9 }, "angle_bounds": { "lower": 0.1, "upper": 0.95 }, } da_area_weight = DistanceAngleAreaNbSetWeight( weight_type="has_intersection", surface_definition=surface_definition, nb_sets_from_hints="fallback_to_source", other_nb_sets="0_weight", additional_condition=DistanceAngleAreaNbSetWeight.AC.ONLY_ACB, ) da_area_weight_2 = DistanceAngleAreaNbSetWeight( weight_type="has_intersection", surface_definition=surface_definition_2, nb_sets_from_hints="fallback_to_source", other_nb_sets="0_weight", additional_condition=DistanceAngleAreaNbSetWeight.AC.ONLY_ACB, ) weight_estimator = { "function": "smootherstep", "options": { "delta_csm_min": 0.5, "delta_csm_max": 3.0 }, } symmetry_measure_type = "csm_wcs_ctwcc" delta_weight = DeltaCSMNbSetWeight( effective_csm_estimator=effective_csm_estimator, weight_estimator=weight_estimator, symmetry_measure_type=symmetry_measure_type, ) bias_weight = CNBiasNbSetWeight.linearly_equidistant(weight_cn1=1.0, weight_cn13=4.0) bias_weight_2 = CNBiasNbSetWeight.linearly_equidistant(weight_cn1=1.0, weight_cn13=5.0) angle_weight = AngleNbSetWeight() nad_weight = NormalizedAngleDistanceNbSetWeight( average_type="geometric", aa=1, bb=1) multi_weights_strategy_1 = MultiWeightsChemenvStrategy( dist_ang_area_weight=da_area_weight, self_csm_weight=self_csm_weight, delta_csm_weight=delta_weight, cn_bias_weight=bias_weight, angle_weight=angle_weight, normalized_angle_distance_weight=nad_weight, symmetry_measure_type=symmetry_measure_type, ) multi_weights_strategy_2 = MultiWeightsChemenvStrategy( dist_ang_area_weight=da_area_weight, self_csm_weight=self_csm_weight, delta_csm_weight=delta_weight, cn_bias_weight=bias_weight_2, angle_weight=angle_weight, normalized_angle_distance_weight=nad_weight, symmetry_measure_type=symmetry_measure_type, ) multi_weights_strategy_3 = MultiWeightsChemenvStrategy( dist_ang_area_weight=da_area_weight_2, self_csm_weight=self_csm_weight, delta_csm_weight=delta_weight, cn_bias_weight=bias_weight, angle_weight=angle_weight, normalized_angle_distance_weight=nad_weight, symmetry_measure_type=symmetry_measure_type, ) multi_weights_strategy_1_from_dict = MultiWeightsChemenvStrategy.from_dict( multi_weights_strategy_1.as_dict()) self.assertTrue( multi_weights_strategy_1 == multi_weights_strategy_1_from_dict) self.assertFalse(simplest_strategy_1 == multi_weights_strategy_1) self.assertFalse(multi_weights_strategy_1 == multi_weights_strategy_2) self.assertFalse(multi_weights_strategy_1 == multi_weights_strategy_3) self.assertFalse(multi_weights_strategy_2 == multi_weights_strategy_3)
def test_light_structure_environments(self): with ScratchDir("."): f = open("{}/{}".format(se_files_dir, 'se_mp-7000.json'), 'r') dd = json.load(f) f.close() se = StructureEnvironments.from_dict(dd) strategy = SimplestChemenvStrategy() lse = LightStructureEnvironments.from_structure_environments( structure_environments=se, strategy=strategy, valences='undefined') isite = 6 nb_set = lse.neighbors_sets[isite][0] neighb_coords = [ np.array([0.2443798, 1.80409653, -1.13218359]), np.array([1.44020353, 1.11368738, 1.13218359]), np.array([2.75513098, 2.54465207, -0.70467298]), np.array([0.82616785, 3.65833945, 0.70467298]) ] neighb_indices = [0, 3, 5, 1] neighb_images = [[0, 0, -1], [0, 0, 0], [0, 0, -1], [0, 0, 0]] np.testing.assert_array_almost_equal(neighb_coords, nb_set.neighb_coords) np.testing.assert_array_almost_equal( neighb_coords, [s.coords for s in nb_set.neighb_sites]) nb_sai = nb_set.neighb_sites_and_indices np.testing.assert_array_almost_equal( neighb_coords, [sai['site'].coords for sai in nb_sai]) np.testing.assert_array_almost_equal( neighb_indices, [sai['index'] for sai in nb_sai]) nb_iai = nb_set.neighb_indices_and_images np.testing.assert_array_almost_equal( neighb_indices, [iai['index'] for iai in nb_iai]) np.testing.assert_array_equal( neighb_images, [iai['image_cell'] for iai in nb_iai]) self.assertEqual(nb_set.__len__(), 4) self.assertEqual(nb_set.__hash__(), 4) self.assertFalse(nb_set.__ne__(nb_set)) self.assertEqual( nb_set.__str__(), 'Neighbors Set for site #6 :\n' ' - Coordination number : 4\n' ' - Neighbors sites indices : 0, 1, 2, 3\n') stats = lse.get_statistics() neighbors = lse.strategy.get_site_neighbors( site=lse.structure[isite]) self.assertArrayAlmostEqual( neighbors[0].coords, np.array([0.2443798, 1.80409653, -1.13218359])) self.assertArrayAlmostEqual( neighbors[1].coords, np.array([1.44020353, 1.11368738, 1.13218359])) self.assertArrayAlmostEqual( neighbors[2].coords, np.array([2.75513098, 2.54465207, -0.70467298])) self.assertArrayAlmostEqual( neighbors[3].coords, np.array([0.82616785, 3.65833945, 0.70467298])) equiv_site_index_and_transform = lse.strategy.equivalent_site_index_and_transform( neighbors[0]) self.assertEqual(equiv_site_index_and_transform[0], 0) self.assertArrayAlmostEqual(equiv_site_index_and_transform[1], [0.0, 0.0, 0.0]) self.assertArrayAlmostEqual(equiv_site_index_and_transform[2], [0.0, 0.0, -1.0]) equiv_site_index_and_transform = lse.strategy.equivalent_site_index_and_transform( neighbors[1]) self.assertEqual(equiv_site_index_and_transform[0], 3) self.assertArrayAlmostEqual(equiv_site_index_and_transform[1], [0.0, 0.0, 0.0]) self.assertArrayAlmostEqual(equiv_site_index_and_transform[2], [0.0, 0.0, 0.0]) self.assertEqual(stats['atom_coordination_environments_present'], {'Si': { 'T:4': 3.0 }}) self.assertEqual(stats['coordination_environments_atom_present'], {'T:4': { 'Si': 3.0 }}) self.assertEqual( stats['fraction_atom_coordination_environments_present'], {'Si': { 'T:4': 1.0 }}) site_info_ce = lse.get_site_info_for_specie_ce(specie=Species( 'Si', 4), ce_symbol='T:4') np.testing.assert_array_almost_equal(site_info_ce['fractions'], [1.0, 1.0, 1.0]) np.testing.assert_array_almost_equal(site_info_ce['csms'], [ 0.009887784240541068, 0.009887786546730826, 0.009887787384385317 ]) self.assertEqual(site_info_ce['isites'], [6, 7, 8]) site_info_allces = lse.get_site_info_for_specie_allces( specie=Species('Si', 4)) self.assertEqual(site_info_allces['T:4'], site_info_ce) self.assertFalse(lse.contains_only_one_anion('I-')) self.assertFalse(lse.contains_only_one_anion_atom('I')) self.assertTrue( lse.site_contains_environment(isite=isite, ce_symbol='T:4')) self.assertFalse( lse.site_contains_environment(isite=isite, ce_symbol='S:4')) self.assertFalse( lse.structure_contains_atom_environment(atom_symbol='Si', ce_symbol='S:4')) self.assertTrue( lse.structure_contains_atom_environment(atom_symbol='Si', ce_symbol='T:4')) self.assertFalse( lse.structure_contains_atom_environment(atom_symbol='O', ce_symbol='T:4')) self.assertTrue(lse.uniquely_determines_coordination_environments) self.assertFalse(lse.__ne__(lse)) envs = lse.strategy.get_site_coordination_environments( lse.structure[6]) self.assertEqual(len(envs), 1) self.assertEqual(envs[0][0], 'T:4') multi_strategy = MultiWeightsChemenvStrategy.stats_article_weights_parameters( ) lse_multi = LightStructureEnvironments.from_structure_environments( strategy=multi_strategy, structure_environments=se, valences='undefined') self.assertAlmostEqual( lse_multi.coordination_environments[isite][0]['csm'], 0.009887784240541068) self.assertAlmostEqual( lse_multi.coordination_environments[isite][0]['ce_fraction'], 1.0) self.assertEqual( lse_multi.coordination_environments[isite][0]['ce_symbol'], 'T:4')
def test_light_structure_environments(self): f = open("{}/{}".format(se_files_dir, 'se_mp-7000.json'), 'r') dd = json.load(f) f.close() se = StructureEnvironments.from_dict(dd) strategy = SimplestChemenvStrategy() lse = LightStructureEnvironments.from_structure_environments(structure_environments=se, strategy=strategy, valences='undefined') isite = 6 nb_set = lse.neighbors_sets[isite][0] neighb_coords = [np.array([0.2443798, 1.80409653, -1.13218359]), np.array([1.44020353, 1.11368738, 1.13218359]), np.array([2.75513098, 2.54465207, -0.70467298]), np.array([0.82616785, 3.65833945, 0.70467298])] neighb_indices = [0, 3, 5, 1] neighb_images = [[0, 0, -1], [0, 0, 0], [0, 0, -1], [0, 0, 0]] np.testing.assert_array_almost_equal(neighb_coords, nb_set.neighb_coords) np.testing.assert_array_almost_equal(neighb_coords, [s.coords for s in nb_set.neighb_sites]) nb_sai = nb_set.neighb_sites_and_indices np.testing.assert_array_almost_equal(neighb_coords, [sai['site'].coords for sai in nb_sai]) np.testing.assert_array_almost_equal(neighb_indices, [sai['index'] for sai in nb_sai]) nb_iai = nb_set.neighb_indices_and_images np.testing.assert_array_almost_equal(neighb_indices, [iai['index'] for iai in nb_iai]) np.testing.assert_array_equal(neighb_images, [iai['image_cell'] for iai in nb_iai]) self.assertEqual(nb_set.__len__(), 4) self.assertEqual(nb_set.__hash__(), 4) self.assertFalse(nb_set.__ne__(nb_set)) self.assertEqual(nb_set.__str__(), 'Neighbors Set for site #6 :\n' ' - Coordination number : 4\n' ' - Neighbors sites indices : 0, 1, 2, 3\n') stats = lse.get_statistics() neighbors = lse.strategy.get_site_neighbors(site=lse.structure[isite]) self.assertArrayAlmostEqual(neighbors[0].coords, np.array([ 0.2443798, 1.80409653, -1.13218359])) self.assertArrayAlmostEqual(neighbors[1].coords, np.array([ 1.44020353, 1.11368738, 1.13218359])) self.assertArrayAlmostEqual(neighbors[2].coords, np.array([ 2.75513098, 2.54465207, -0.70467298])) self.assertArrayAlmostEqual(neighbors[3].coords, np.array([ 0.82616785, 3.65833945, 0.70467298])) equiv_site_index_and_transform = lse.strategy.equivalent_site_index_and_transform(neighbors[0]) self.assertEqual(equiv_site_index_and_transform[0], 0) self.assertArrayAlmostEqual(equiv_site_index_and_transform[1], [0.0, 0.0, 0.0]) self.assertArrayAlmostEqual(equiv_site_index_and_transform[2], [0.0, 0.0, -1.0]) equiv_site_index_and_transform = lse.strategy.equivalent_site_index_and_transform(neighbors[1]) self.assertEqual(equiv_site_index_and_transform[0], 3) self.assertArrayAlmostEqual(equiv_site_index_and_transform[1], [0.0, 0.0, 0.0]) self.assertArrayAlmostEqual(equiv_site_index_and_transform[2], [0.0, 0.0, 0.0]) self.assertEqual(stats['atom_coordination_environments_present'], {'Si': {'T:4': 3.0}}) self.assertEqual(stats['coordination_environments_atom_present'], {'T:4': {'Si': 3.0}}) self.assertEqual(stats['fraction_atom_coordination_environments_present'], {'Si': {'T:4': 1.0}}) site_info_ce = lse.get_site_info_for_specie_ce(specie=Specie('Si', 4), ce_symbol='T:4') np.testing.assert_array_almost_equal(site_info_ce['fractions'], [1.0, 1.0, 1.0]) np.testing.assert_array_almost_equal(site_info_ce['csms'], [0.009887784240541068, 0.009887786546730826, 0.009887787384385317]) self.assertEqual(site_info_ce['isites'], [6, 7, 8]) site_info_allces = lse.get_site_info_for_specie_allces(specie=Specie('Si', 4)) self.assertEqual(site_info_allces['T:4'], site_info_ce) self.assertFalse(lse.contains_only_one_anion('I-')) self.assertFalse(lse.contains_only_one_anion_atom('I')) self.assertTrue(lse.site_contains_environment(isite=isite, ce_symbol='T:4')) self.assertFalse(lse.site_contains_environment(isite=isite, ce_symbol='S:4')) self.assertFalse(lse.structure_contains_atom_environment(atom_symbol='Si', ce_symbol='S:4')) self.assertTrue(lse.structure_contains_atom_environment(atom_symbol='Si', ce_symbol='T:4')) self.assertFalse(lse.structure_contains_atom_environment(atom_symbol='O', ce_symbol='T:4')) self.assertTrue(lse.uniquely_determines_coordination_environments) self.assertFalse(lse.__ne__(lse)) envs = lse.strategy.get_site_coordination_environments(lse.structure[6]) self.assertEqual(len(envs), 1) self.assertEqual(envs[0][0], 'T:4') multi_strategy = MultiWeightsChemenvStrategy.stats_article_weights_parameters() lse_multi = LightStructureEnvironments.from_structure_environments(strategy=multi_strategy, structure_environments=se, valences='undefined') self.assertAlmostEqual(lse_multi.coordination_environments[isite][0]['csm'], 0.009887784240541068) self.assertAlmostEqual(lse_multi.coordination_environments[isite][0]['ce_fraction'], 1.0) self.assertEqual(lse_multi.coordination_environments[isite][0]['ce_symbol'], 'T:4')
print("RUNNING!") atoms = row.toatoms() Ir_indices = [ i for i, s in enumerate(atoms.get_chemical_symbols()) if s == 'Ir' ] struct = AseAtomsAdaptor.get_structure(atoms) lgf = LocalGeometryFinder() lgf.setup_structure(structure=struct) se = lgf.compute_structure_environments(maximum_distance_factor=1.41, only_cations=False) strategy = MultiWeightsChemenvStrategy.stats_article_weights_parameters( ) lse = LightStructureEnvironments.from_structure_environments( strategy=strategy, structure_environments=se) isite = 0 cor_env = [] for isite in Ir_indices: c_env = lse.coordination_environments[isite] if len(c_env) == 0: continue cor_env += [c_env[0]['ce_symbol']] if len(cor_env) == 0: continue
def test_strategies(self): simplest_strategy_1 = SimplestChemenvStrategy() simplest_strategy_2 = SimplestChemenvStrategy(distance_cutoff=1.5, angle_cutoff=0.5) self.assertFalse(simplest_strategy_1 == simplest_strategy_2) simplest_strategy_1_from_dict = SimplestChemenvStrategy.from_dict(simplest_strategy_1.as_dict()) self.assertTrue(simplest_strategy_1, simplest_strategy_1_from_dict) effective_csm_estimator = {'function': 'power2_inverse_decreasing', 'options': {'max_csm': 8.0}} self_csm_weight = SelfCSMNbSetWeight() surface_definition = {'type': 'standard_elliptic', 'distance_bounds': {'lower': 1.1, 'upper': 1.9}, 'angle_bounds': {'lower': 0.1, 'upper': 0.9}} surface_definition_2 = {'type': 'standard_elliptic', 'distance_bounds': {'lower': 1.1, 'upper': 1.9}, 'angle_bounds': {'lower': 0.1, 'upper': 0.95}} da_area_weight = DistanceAngleAreaNbSetWeight(weight_type='has_intersection', surface_definition=surface_definition, nb_sets_from_hints='fallback_to_source', other_nb_sets='0_weight', additional_condition=DistanceAngleAreaNbSetWeight.AC.ONLY_ACB) da_area_weight_2 = DistanceAngleAreaNbSetWeight(weight_type='has_intersection', surface_definition=surface_definition_2, nb_sets_from_hints='fallback_to_source', other_nb_sets='0_weight', additional_condition=DistanceAngleAreaNbSetWeight.AC.ONLY_ACB) weight_estimator = {'function': 'smootherstep', 'options': {'delta_csm_min': 0.5, 'delta_csm_max': 3.0}} symmetry_measure_type = 'csm_wcs_ctwcc' delta_weight = DeltaCSMNbSetWeight(effective_csm_estimator=effective_csm_estimator, weight_estimator=weight_estimator, symmetry_measure_type=symmetry_measure_type) bias_weight = CNBiasNbSetWeight.linearly_equidistant(weight_cn1=1.0, weight_cn13=4.0) bias_weight_2 = CNBiasNbSetWeight.linearly_equidistant(weight_cn1=1.0, weight_cn13=5.0) angle_weight = AngleNbSetWeight() nad_weight = NormalizedAngleDistanceNbSetWeight(average_type='geometric', aa=1, bb=1) multi_weights_strategy_1 = MultiWeightsChemenvStrategy(dist_ang_area_weight=da_area_weight, self_csm_weight=self_csm_weight, delta_csm_weight=delta_weight, cn_bias_weight=bias_weight, angle_weight=angle_weight, normalized_angle_distance_weight=nad_weight, symmetry_measure_type=symmetry_measure_type) multi_weights_strategy_2 = MultiWeightsChemenvStrategy(dist_ang_area_weight=da_area_weight, self_csm_weight=self_csm_weight, delta_csm_weight=delta_weight, cn_bias_weight=bias_weight_2, angle_weight=angle_weight, normalized_angle_distance_weight=nad_weight, symmetry_measure_type=symmetry_measure_type) multi_weights_strategy_3 = MultiWeightsChemenvStrategy(dist_ang_area_weight=da_area_weight_2, self_csm_weight=self_csm_weight, delta_csm_weight=delta_weight, cn_bias_weight=bias_weight, angle_weight=angle_weight, normalized_angle_distance_weight=nad_weight, symmetry_measure_type=symmetry_measure_type) multi_weights_strategy_1_from_dict = MultiWeightsChemenvStrategy.from_dict(multi_weights_strategy_1.as_dict()) self.assertTrue(multi_weights_strategy_1 == multi_weights_strategy_1_from_dict) self.assertFalse(simplest_strategy_1 == multi_weights_strategy_1) self.assertFalse(multi_weights_strategy_1 == multi_weights_strategy_2) self.assertFalse(multi_weights_strategy_1 == multi_weights_strategy_3) self.assertFalse(multi_weights_strategy_2 == multi_weights_strategy_3)
def figure_fractions(self, weights_options, morphing_factors=None): if morphing_factors is None: morphing_factors = np.linspace(1.0, 2.0, 21) # Set up the local geometry finder lgf = LocalGeometryFinder() lgf.setup_parameters( structure_refinement=lgf.STRUCTURE_REFINEMENT_NONE) # Set up the weights for the MultiWeights strategy weights = self.get_weights(weights_options) # Set up the strategy strat = MultiWeightsChemenvStrategy( dist_ang_area_weight=weights['DistAngArea'], self_csm_weight=weights['SelfCSM'], delta_csm_weight=weights['DeltaCSM'], cn_bias_weight=weights['CNBias'], angle_weight=weights['Angle'], normalized_angle_distance_weight=weights['NormalizedAngDist']) fake_valences = [-1] * ( self.coordination_geometry.coordination_number + 1) fake_valences[0] = 1 fractions_initial_environment = np.zeros_like(morphing_factors) fractions_final_environment = np.zeros_like(morphing_factors) for ii, morphing_factor in enumerate(morphing_factors): print(ii) struct = self.get_structure(morphing_factor=morphing_factor) print(struct) # Get the StructureEnvironments lgf.setup_structure(structure=struct) se = lgf.compute_structure_environments(only_indices=[0], valences=fake_valences) strat.set_structure_environments(structure_environments=se) result = strat.get_site_coordination_environments_fractions( site=se.structure[0], isite=0, return_strategy_dict_info=True, return_all=True) for res in result: if res['ce_symbol'] == self.initial_environment_symbol: fractions_initial_environment[ii] = res['ce_fraction'] elif res[ 'ce_symbol'] == self.expected_final_environment_symbol: fractions_final_environment[ii] = res['ce_fraction'] fig_width_cm = 8.25 fig_height_cm = 7.0 fig_width = fig_width_cm / 2.54 fig_height = fig_height_cm / 2.54 fig = plt.figure(num=1, figsize=(fig_width, fig_height)) subplot = fig.add_subplot(111) subplot.plot(morphing_factors, fractions_initial_environment, 'b-', label='{}'.format(self.initial_environment_symbol), linewidth=1.5) subplot.plot(morphing_factors, fractions_final_environment, 'g--', label='{}'.format(self.expected_final_environment_symbol), linewidth=1.5) plt.legend(fontsize=8.0, loc=7) plt.show()
def test_strategies(self): simplest_strategy_1 = SimplestChemenvStrategy() simplest_strategy_2 = SimplestChemenvStrategy(distance_cutoff=1.5, angle_cutoff=0.5) self.assertFalse(simplest_strategy_1 == simplest_strategy_2) simplest_strategy_1_from_dict = SimplestChemenvStrategy.from_dict( simplest_strategy_1.as_dict()) self.assertTrue(simplest_strategy_1, simplest_strategy_1_from_dict) effective_csm_estimator = { 'function': 'power2_inverse_decreasing', 'options': { 'max_csm': 8.0 } } self_csm_weight = SelfCSMNbSetWeight() surface_definition = { 'type': 'standard_elliptic', 'distance_bounds': { 'lower': 1.1, 'upper': 1.9 }, 'angle_bounds': { 'lower': 0.1, 'upper': 0.9 } } surface_definition_2 = { 'type': 'standard_elliptic', 'distance_bounds': { 'lower': 1.1, 'upper': 1.9 }, 'angle_bounds': { 'lower': 0.1, 'upper': 0.95 } } da_area_weight = DistanceAngleAreaNbSetWeight( weight_type='has_intersection', surface_definition=surface_definition, nb_sets_from_hints='fallback_to_source', other_nb_sets='0_weight', additional_condition=DistanceAngleAreaNbSetWeight.AC.ONLY_ACB) da_area_weight_2 = DistanceAngleAreaNbSetWeight( weight_type='has_intersection', surface_definition=surface_definition_2, nb_sets_from_hints='fallback_to_source', other_nb_sets='0_weight', additional_condition=DistanceAngleAreaNbSetWeight.AC.ONLY_ACB) weight_estimator = { 'function': 'smootherstep', 'options': { 'delta_csm_min': 0.5, 'delta_csm_max': 3.0 } } symmetry_measure_type = 'csm_wcs_ctwcc' delta_weight = DeltaCSMNbSetWeight( effective_csm_estimator=effective_csm_estimator, weight_estimator=weight_estimator, symmetry_measure_type=symmetry_measure_type) bias_weight = CNBiasNbSetWeight.linearly_equidistant(weight_cn1=1.0, weight_cn13=4.0) bias_weight_2 = CNBiasNbSetWeight.linearly_equidistant(weight_cn1=1.0, weight_cn13=5.0) angle_weight = AngleNbSetWeight() nad_weight = NormalizedAngleDistanceNbSetWeight( average_type='geometric', aa=1, bb=1) multi_weights_strategy_1 = MultiWeightsChemenvStrategy( dist_ang_area_weight=da_area_weight, self_csm_weight=self_csm_weight, delta_csm_weight=delta_weight, cn_bias_weight=bias_weight, angle_weight=angle_weight, normalized_angle_distance_weight=nad_weight, symmetry_measure_type=symmetry_measure_type) multi_weights_strategy_2 = MultiWeightsChemenvStrategy( dist_ang_area_weight=da_area_weight, self_csm_weight=self_csm_weight, delta_csm_weight=delta_weight, cn_bias_weight=bias_weight_2, angle_weight=angle_weight, normalized_angle_distance_weight=nad_weight, symmetry_measure_type=symmetry_measure_type) multi_weights_strategy_3 = MultiWeightsChemenvStrategy( dist_ang_area_weight=da_area_weight_2, self_csm_weight=self_csm_weight, delta_csm_weight=delta_weight, cn_bias_weight=bias_weight, angle_weight=angle_weight, normalized_angle_distance_weight=nad_weight, symmetry_measure_type=symmetry_measure_type) multi_weights_strategy_1_from_dict = MultiWeightsChemenvStrategy.from_dict( multi_weights_strategy_1.as_dict()) self.assertTrue( multi_weights_strategy_1 == multi_weights_strategy_1_from_dict) self.assertFalse(simplest_strategy_1 == multi_weights_strategy_1) self.assertFalse(multi_weights_strategy_1 == multi_weights_strategy_2) self.assertFalse(multi_weights_strategy_1 == multi_weights_strategy_3) self.assertFalse(multi_weights_strategy_2 == multi_weights_strategy_3)
def test_light_structure_environments(self): with ScratchDir("."): with open(f"{se_files_dir}/se_mp-7000.json") as f: dd = json.load(f) se = StructureEnvironments.from_dict(dd) strategy = SimplestChemenvStrategy() lse = LightStructureEnvironments.from_structure_environments( structure_environments=se, strategy=strategy, valences="undefined") isite = 6 nb_set = lse.neighbors_sets[isite][0] neighb_coords = [ np.array([0.2443798, 1.80409653, -1.13218359]), np.array([1.44020353, 1.11368738, 1.13218359]), np.array([2.75513098, 2.54465207, -0.70467298]), np.array([0.82616785, 3.65833945, 0.70467298]), ] neighb_indices = [0, 3, 5, 1] neighb_images = [[0, 0, -1], [0, 0, 0], [0, 0, -1], [0, 0, 0]] np.testing.assert_array_almost_equal(neighb_coords, nb_set.neighb_coords) np.testing.assert_array_almost_equal( neighb_coords, [s.coords for s in nb_set.neighb_sites]) nb_sai = nb_set.neighb_sites_and_indices np.testing.assert_array_almost_equal( neighb_coords, [sai["site"].coords for sai in nb_sai]) np.testing.assert_array_almost_equal( neighb_indices, [sai["index"] for sai in nb_sai]) nb_iai = nb_set.neighb_indices_and_images np.testing.assert_array_almost_equal( neighb_indices, [iai["index"] for iai in nb_iai]) np.testing.assert_array_equal( neighb_images, [iai["image_cell"] for iai in nb_iai]) self.assertEqual(nb_set.__len__(), 4) self.assertEqual(nb_set.__hash__(), 4) self.assertFalse(nb_set.__ne__(nb_set)) self.assertEqual( nb_set.__str__(), "Neighbors Set for site #6 :\n" " - Coordination number : 4\n" " - Neighbors sites indices : 0, 1, 2, 3\n", ) stats = lse.get_statistics() neighbors = lse.strategy.get_site_neighbors( site=lse.structure[isite]) self.assertArrayAlmostEqual( neighbors[0].coords, np.array([0.2443798, 1.80409653, -1.13218359])) self.assertArrayAlmostEqual( neighbors[1].coords, np.array([1.44020353, 1.11368738, 1.13218359])) self.assertArrayAlmostEqual( neighbors[2].coords, np.array([2.75513098, 2.54465207, -0.70467298])) self.assertArrayAlmostEqual( neighbors[3].coords, np.array([0.82616785, 3.65833945, 0.70467298])) equiv_site_index_and_transform = lse.strategy.equivalent_site_index_and_transform( neighbors[0]) self.assertEqual(equiv_site_index_and_transform[0], 0) self.assertArrayAlmostEqual(equiv_site_index_and_transform[1], [0.0, 0.0, 0.0]) self.assertArrayAlmostEqual(equiv_site_index_and_transform[2], [0.0, 0.0, -1.0]) equiv_site_index_and_transform = lse.strategy.equivalent_site_index_and_transform( neighbors[1]) self.assertEqual(equiv_site_index_and_transform[0], 3) self.assertArrayAlmostEqual(equiv_site_index_and_transform[1], [0.0, 0.0, 0.0]) self.assertArrayAlmostEqual(equiv_site_index_and_transform[2], [0.0, 0.0, 0.0]) self.assertEqual(stats["atom_coordination_environments_present"], {"Si": { "T:4": 3.0 }}) self.assertEqual(stats["coordination_environments_atom_present"], {"T:4": { "Si": 3.0 }}) self.assertEqual( stats["fraction_atom_coordination_environments_present"], {"Si": { "T:4": 1.0 }}, ) site_info_ce = lse.get_site_info_for_specie_ce(specie=Species( "Si", 4), ce_symbol="T:4") np.testing.assert_array_almost_equal(site_info_ce["fractions"], [1.0, 1.0, 1.0]) np.testing.assert_array_almost_equal( site_info_ce["csms"], [ 0.009887784240541068, 0.009887786546730826, 0.009887787384385317 ], ) self.assertEqual(site_info_ce["isites"], [6, 7, 8]) site_info_allces = lse.get_site_info_for_specie_allces( specie=Species("Si", 4)) self.assertEqual(site_info_allces["T:4"], site_info_ce) self.assertFalse(lse.contains_only_one_anion("I-")) self.assertFalse(lse.contains_only_one_anion_atom("I")) self.assertTrue( lse.site_contains_environment(isite=isite, ce_symbol="T:4")) self.assertFalse( lse.site_contains_environment(isite=isite, ce_symbol="S:4")) self.assertFalse( lse.structure_contains_atom_environment(atom_symbol="Si", ce_symbol="S:4")) self.assertTrue( lse.structure_contains_atom_environment(atom_symbol="Si", ce_symbol="T:4")) self.assertFalse( lse.structure_contains_atom_environment(atom_symbol="O", ce_symbol="T:4")) self.assertTrue(lse.uniquely_determines_coordination_environments) self.assertFalse(lse.__ne__(lse)) envs = lse.strategy.get_site_coordination_environments( lse.structure[6]) self.assertEqual(len(envs), 1) self.assertEqual(envs[0][0], "T:4") multi_strategy = MultiWeightsChemenvStrategy.stats_article_weights_parameters( ) lse_multi = LightStructureEnvironments.from_structure_environments( strategy=multi_strategy, structure_environments=se, valences="undefined") self.assertAlmostEqual( lse_multi.coordination_environments[isite][0]["csm"], 0.009887784240541068, ) self.assertAlmostEqual( lse_multi.coordination_environments[isite][0]["ce_fraction"], 1.0) self.assertEqual( lse_multi.coordination_environments[isite][0]["ce_symbol"], "T:4")