本文整理汇总了Python中pymatgen.analysis.structure_matcher.StructureMatcher.fit方法的典型用法代码示例。如果您正苦于以下问题:Python StructureMatcher.fit方法的具体用法?Python StructureMatcher.fit怎么用?Python StructureMatcher.fit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymatgen.analysis.structure_matcher.StructureMatcher
的用法示例。
在下文中一共展示了StructureMatcher.fit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_disordered_primitive_to_ordered_supercell
# 需要导入模块: from pymatgen.analysis.structure_matcher import StructureMatcher [as 别名]
# 或者: from pymatgen.analysis.structure_matcher.StructureMatcher import fit [as 别名]
def test_disordered_primitive_to_ordered_supercell(self):
sm_atoms = StructureMatcher(ltol=0.2, stol=0.3, angle_tol=5,
primitive_cell=False, scale=True,
attempt_supercell=True,
allow_subset=True,
supercell_size = 'num_atoms',
comparator=OrderDisorderElementComparator())
sm_sites = StructureMatcher(ltol=0.2, stol=0.3, angle_tol=5,
primitive_cell=False, scale=True,
attempt_supercell=True,
allow_subset=True,
supercell_size = 'num_sites',
comparator=OrderDisorderElementComparator())
lp = Lattice.orthorhombic(10, 20, 30)
pcoords = [[0, 0, 0],
[0.5, 0.5, 0.5]]
ls = Lattice.orthorhombic(20,20,30)
scoords = [[0, 0, 0],
[0.75, 0.5, 0.5]]
prim = Structure(lp, [{'Na':0.5}, {'Cl':0.5}], pcoords)
supercell = Structure(ls, ['Na', 'Cl'], scoords)
supercell.make_supercell([[-1,1,0],[0,1,1],[1,0,0]])
self.assertFalse(sm_sites.fit(prim, supercell))
self.assertTrue(sm_atoms.fit(prim, supercell))
self.assertRaises(ValueError, sm_atoms.get_s2_like_s1, prim, supercell)
self.assertEqual(len(sm_atoms.get_s2_like_s1(supercell, prim)), 4)
示例2: test_ordered_primitive_to_disordered_supercell
# 需要导入模块: from pymatgen.analysis.structure_matcher import StructureMatcher [as 别名]
# 或者: from pymatgen.analysis.structure_matcher.StructureMatcher import fit [as 别名]
def test_ordered_primitive_to_disordered_supercell(self):
sm_atoms = StructureMatcher(ltol=0.2, stol=0.3, angle_tol=5,
primitive_cell=False, scale=True,
attempt_supercell=True,
allow_subset=True,
supercell_size = 'num_atoms',
comparator=OrderDisorderElementComparator())
sm_sites = StructureMatcher(ltol=0.2, stol=0.3, angle_tol=5,
primitive_cell=False, scale=True,
attempt_supercell=True,
allow_subset=True,
supercell_size = 'num_sites',
comparator=OrderDisorderElementComparator())
lp = Lattice.orthorhombic(10, 20, 30)
pcoords = [[0, 0, 0],
[0.5, 0.5, 0.5]]
ls = Lattice.orthorhombic(20,20,30)
scoords = [[0, 0, 0],
[0.5, 0, 0],
[0.25, 0.5, 0.5],
[0.75, 0.5, 0.5]]
s1 = Structure(lp, ['Na', 'Cl'], pcoords)
s2 = Structure(ls, [{'Na':0.5}, {'Na':0.5}, {'Cl':0.5}, {'Cl':0.5}], scoords)
self.assertTrue(sm_sites.fit(s1, s2))
self.assertFalse(sm_atoms.fit(s1, s2))
示例3: add_if_belongs
# 需要导入模块: from pymatgen.analysis.structure_matcher import StructureMatcher [as 别名]
# 或者: from pymatgen.analysis.structure_matcher.StructureMatcher import fit [as 别名]
def add_if_belongs(self, cand_snl):
# no need to compare if different formulas or spacegroups
if cand_snl.snlgroup_key != self.canonical_snl.snlgroup_key:
return False, None
# no need to compare if one is ordered, the other disordered
if not (cand_snl.structure.is_ordered == self.canonical_structure.is_ordered):
return False, None
# filter out large C-Ce structures
comp = cand_snl.structure.composition
elsyms = sorted(set([e.symbol for e in comp.elements]))
chemsys = '-'.join(elsyms)
if (
cand_snl.structure.num_sites > 1500 or self.canonical_structure.num_sites > 1500) and chemsys == 'C-Ce':
print 'SKIPPING LARGE C-Ce'
return False, None
# make sure the structure is not already in all_structures
if cand_snl.snl_id in self.all_snl_ids:
print 'WARNING: add_if_belongs() has detected that you are trying to add the same SNL id twice!'
return False, None
#try a structure fit to the canonical structure
# use default Structure Matcher params from April 24, 2013, as suggested by Shyue
# we are using the ElementComparator() because this is how we want to group results
sm = StructureMatcher(ltol=0.2, stol=0.3, angle_tol=5, primitive_cell=True, scale=True,
attempt_supercell=False, comparator=ElementComparator())
if not sm.fit(cand_snl.structure, self.canonical_structure):
return False, None
# everything checks out, add to the group
self.all_snl_ids.append(cand_snl.snl_id)
# now that we are in the group, if there are site properties we need to check species_groups
# e.g., if there is another SNL in the group with the same site properties, e.g. MAGMOM
spec_group = None
if has_species_properties(cand_snl.structure):
for snl in self.species_snl:
sms = StructureMatcher(ltol=0.2, stol=0.3, angle_tol=5, primitive_cell=True, scale=True,
attempt_supercell=False, comparator=SpeciesComparator())
if sms.fit(cand_snl.structure, snl.structure):
spec_group = snl.snl_id
self.species_groups[snl.snl_id].append(cand_snl.snl_id)
break
# add a new species group
if not spec_group:
self.species_groups[cand_snl.snl_id] = [cand_snl.snl_id]
self.species_snl.append(cand_snl)
spec_group = cand_snl.snl_id
self.updated_at = datetime.datetime.utcnow()
return True, spec_group
示例4: test_supercell_fit
# 需要导入模块: from pymatgen.analysis.structure_matcher import StructureMatcher [as 别名]
# 或者: from pymatgen.analysis.structure_matcher.StructureMatcher import fit [as 别名]
def test_supercell_fit(self):
sm = StructureMatcher(attempt_supercell=False)
s1 = read_structure(os.path.join(test_dir, "Al3F9.cif"))
s2 = read_structure(os.path.join(test_dir, "Al3F9_distorted.cif"))
self.assertFalse(sm.fit(s1, s2))
sm = StructureMatcher(attempt_supercell=True)
self.assertTrue(sm.fit(s1, s2))
示例5: test_supercell_fit
# 需要导入模块: from pymatgen.analysis.structure_matcher import StructureMatcher [as 别名]
# 或者: from pymatgen.analysis.structure_matcher.StructureMatcher import fit [as 别名]
def test_supercell_fit(self):
sm = StructureMatcher(attempt_supercell=False)
s1 = Structure.from_file(os.path.join(test_dir, "Al3F9.json"))
s2 = Structure.from_file(os.path.join(test_dir, "Al3F9_distorted.json"))
self.assertFalse(sm.fit(s1, s2))
sm = StructureMatcher(attempt_supercell=True)
self.assertTrue(sm.fit(s1, s2))
self.assertTrue(sm.fit(s2, s1))
示例6: test_primitive
# 需要导入模块: from pymatgen.analysis.structure_matcher import StructureMatcher [as 别名]
# 或者: from pymatgen.analysis.structure_matcher.StructureMatcher import fit [as 别名]
def test_primitive(self):
"""Test primitive cell reduction"""
sm = StructureMatcher(primitive_cell=True)
mod = SupercellMaker(self.struct_list[1],
scaling_matrix=[[2, 0, 0], [0, 3, 0], [0, 0, 1]])
super_cell = mod.modified_structure
self.assertTrue(sm.fit(self.struct_list[0], super_cell))
示例7: structure_transform
# 需要导入模块: from pymatgen.analysis.structure_matcher import StructureMatcher [as 别名]
# 或者: from pymatgen.analysis.structure_matcher.StructureMatcher import fit [as 别名]
def structure_transform(self, original_structure, new_structure,
refine_rotation=True):
"""
Transforms a tensor from one basis for an original structure
into a new basis defined by a new structure.
Args:
original_structure (Structure): structure corresponding
to the basis of the current tensor
new_structure (Structure): structure corresponding to the
desired basis
refine_rotation (bool): whether to refine the rotations
generated in get_ieee_rotation
Returns:
Tensor that has been transformed such that its basis
corresponds to the new_structure's basis
"""
sm = StructureMatcher()
if not sm.fit(original_structure, new_structure):
warnings.warn("original and new structures do not match!")
trans_1 = self.get_ieee_rotation(original_structure, refine_rotation)
trans_2 = self.get_ieee_rotation(new_structure, refine_rotation)
# Get the ieee format tensor
new = self.rotate(trans_1)
# Reverse the ieee format rotation for the second structure
new = new.rotate(np.transpose(trans_2))
return new
示例8: _match_material
# 需要导入模块: from pymatgen.analysis.structure_matcher import StructureMatcher [as 别名]
# 或者: from pymatgen.analysis.structure_matcher.StructureMatcher import fit [as 别名]
def _match_material(self, taskdoc):
"""
Returns the material_id that has the same structure as this task as
determined by the structure matcher. Returns None if no match.
Args:
taskdoc (dict): a JSON-like task document
Returns:
(int) matching material_id or None
"""
formula = taskdoc["formula_reduced_abc"]
if "parent_structure" in taskdoc: # this is used to intentionally combine multiple data w/same formula but slightly different structure, e.g. from an ordering scheme
t_struct = Structure.from_dict(taskdoc["parent_structure"]["structure"])
q = {"formula_reduced_abc": formula, "parent_structure.spacegroup.number": taskdoc["parent_structure"]["spacegroup"]["number"]}
else:
sgnum = taskdoc["output"]["spacegroup"]["number"]
t_struct = Structure.from_dict(taskdoc["output"]["structure"])
q = {"formula_reduced_abc": formula, "sg_number": sgnum}
for m in self._materials.find(q, {"parent_structure": 1, "structure": 1, "material_id": 1}):
s_dict = m["parent_structure"]["structure"] if "parent_structure" in m else m["structure"]
m_struct = Structure.from_dict(s_dict)
sm = StructureMatcher(ltol=0.2, stol=0.3, angle_tol=5,
primitive_cell=True, scale=True,
attempt_supercell=False, allow_subset=False,
comparator=ElementComparator())
if sm.fit(m_struct, t_struct):
return m["material_id"]
return None
示例9: add_if_belongs
# 需要导入模块: from pymatgen.analysis.structure_matcher import StructureMatcher [as 别名]
# 或者: from pymatgen.analysis.structure_matcher.StructureMatcher import fit [as 别名]
def add_if_belongs(self, cand_snl):
# no need to compare if different formulas or spacegroups
if cand_snl.snlgroup_key != self.canonical_snl.snlgroup_key:
return False
# no need to compare if one is ordered, the other disordered
if not (cand_snl.structure.is_ordered == self.canonical_structure.is_ordered):
return False
# make sure the structure is not already in all_structures
if cand_snl.snl_id in self.all_snl_ids:
print 'WARNING: add_if_belongs() has detected that you are trying to add the same SNL id twice!'
return False
#try a structure fit to the canonical structure
# use default Structure Matcher params from April 24, 2013, as suggested by Shyue
# we are using the ElementComparator() because this is how we want to group results
sm = StructureMatcher(ltol=0.2, stol=0.3, angle_tol=5, primitive_cell=True, scale=True, attempt_supercell=True, comparator=ElementComparator())
if not sm.fit(cand_snl.structure, self.canonical_structure):
return False
# everything checks out, add to the group
self.all_snl_ids.append(cand_snl.snl_id)
self.updated_at = datetime.datetime.utcnow()
return True
示例10: test_no_scaling
# 需要导入模块: from pymatgen.analysis.structure_matcher import StructureMatcher [as 别名]
# 或者: from pymatgen.analysis.structure_matcher.StructureMatcher import fit [as 别名]
def test_no_scaling(self):
sm = StructureMatcher(ltol=0.1, stol=0.1, angle_tol=2,
scale=False, comparator=ElementComparator())
self.assertTrue(sm.fit(self.struct_list[0], self.struct_list[1]))
self.assertTrue(sm.get_rms_dist(self.struct_list[0],
self.struct_list[1])[0] < 0.0008)
示例11: _match_material
# 需要导入模块: from pymatgen.analysis.structure_matcher import StructureMatcher [as 别名]
# 或者: from pymatgen.analysis.structure_matcher.StructureMatcher import fit [as 别名]
def _match_material(self, doc):
"""
Returns the material_id that has the same structure as this doc as
determined by the structure matcher. Returns None if no match.
Args:
doc: a JSON-like document
Returns:
(int) matching material_id or None
"""
formula = doc["formula_reduced_abc"]
sgnum = doc["spacegroup"]["number"]
for m in self._materials.find({"formula_reduced_abc": formula, "sg_number": sgnum},
{"structure": 1, "material_id": 1}):
m_struct = Structure.from_dict(m["structure"])
t_struct = Structure.from_dict(doc["structure"])
sm = StructureMatcher(ltol=0.2, stol=0.3, angle_tol=5,
primitive_cell=True, scale=True,
attempt_supercell=False, allow_subset=False,
comparator=ElementComparator())
if sm.fit(m_struct, t_struct):
return m["material_id"]
return None
示例12: _perform_grouping
# 需要导入模块: from pymatgen.analysis.structure_matcher import StructureMatcher [as 别名]
# 或者: from pymatgen.analysis.structure_matcher.StructureMatcher import fit [as 别名]
def _perform_grouping(args):
(entries_json, hosts_json, ltol, stol, angle_tol,
primitive_cell, scale, comparator, groups) = args
entries = json.loads(entries_json, cls=MontyDecoder)
hosts = json.loads(hosts_json, cls=MontyDecoder)
unmatched = list(zip(entries, hosts))
while len(unmatched) > 0:
ref_host = unmatched[0][1]
logger.info(
"Reference tid = {}, formula = {}".format(unmatched[0][0].entry_id,
ref_host.formula)
)
ref_formula = ref_host.composition.reduced_formula
logger.info("Reference host = {}".format(ref_formula))
matches = [unmatched[0]]
for i in range(1, len(unmatched)):
test_host = unmatched[i][1]
logger.info("Testing tid = {}, formula = {}"
.format(unmatched[i][0].entry_id, test_host.formula))
test_formula = test_host.composition.reduced_formula
logger.info("Test host = {}".format(test_formula))
m = StructureMatcher(ltol=ltol, stol=stol, angle_tol=angle_tol,
primitive_cell=primitive_cell, scale=scale,
comparator=comparator)
if m.fit(ref_host, test_host):
logger.info("Fit found")
matches.append(unmatched[i])
groups.append(json.dumps([m[0] for m in matches], cls=MontyEncoder))
unmatched = list(filter(lambda x: x not in matches, unmatched))
logger.info("{} unmatched remaining".format(len(unmatched)))
示例13: test_get_lattice_from_lattice_type
# 需要导入模块: from pymatgen.analysis.structure_matcher import StructureMatcher [as 别名]
# 或者: from pymatgen.analysis.structure_matcher.StructureMatcher import fit [as 别名]
def test_get_lattice_from_lattice_type(self):
cif_structure = """#generated using pymatgen
data_FePO4
_symmetry_space_group_name_H-M Pnma
_cell_length_a 10.41176687
_cell_length_b 6.06717188
_cell_length_c 4.75948954
_chemical_formula_structural FePO4
_chemical_formula_sum 'Fe4 P4 O16'
_cell_volume 300.65685512
_cell_formula_units_Z 4
_symmetry_cell_setting Orthorhombic
loop_
_symmetry_equiv_pos_site_id
_symmetry_equiv_pos_as_xyz
1 'x, y, z'
loop_
_atom_site_type_symbol
_atom_site_label
_atom_site_symmetry_multiplicity
_atom_site_fract_x
_atom_site_fract_y
_atom_site_fract_z
_atom_site_occupancy
Fe Fe1 1 0.218728 0.750000 0.474867 1
Fe Fe2 1 0.281272 0.250000 0.974867 1
Fe Fe3 1 0.718728 0.750000 0.025133 1
Fe Fe4 1 0.781272 0.250000 0.525133 1
P P5 1 0.094613 0.250000 0.418243 1
P P6 1 0.405387 0.750000 0.918243 1
P P7 1 0.594613 0.250000 0.081757 1
P P8 1 0.905387 0.750000 0.581757 1
O O9 1 0.043372 0.750000 0.707138 1
O O10 1 0.096642 0.250000 0.741320 1
O O11 1 0.165710 0.046072 0.285384 1
O O12 1 0.165710 0.453928 0.285384 1
O O13 1 0.334290 0.546072 0.785384 1
O O14 1 0.334290 0.953928 0.785384 1
O O15 1 0.403358 0.750000 0.241320 1
O O16 1 0.456628 0.250000 0.207138 1
O O17 1 0.543372 0.750000 0.792862 1
O O18 1 0.596642 0.250000 0.758680 1
O O19 1 0.665710 0.046072 0.214616 1
O O20 1 0.665710 0.453928 0.214616 1
O O21 1 0.834290 0.546072 0.714616 1
O O22 1 0.834290 0.953928 0.714616 1
O O23 1 0.903358 0.750000 0.258680 1
O O24 1 0.956628 0.250000 0.292862 1
"""
cp = CifParser.from_string(cif_structure)
s_test = cp.get_structures(False)[0]
filepath = os.path.join(test_dir, 'POSCAR')
poscar = Poscar.from_file(filepath)
s_ref = poscar.structure
sm = StructureMatcher(stol=0.05, ltol=0.01, angle_tol=0.1)
self.assertTrue(sm.fit(s_ref, s_test))
示例14: test_fit
# 需要导入模块: from pymatgen.analysis.structure_matcher import StructureMatcher [as 别名]
# 或者: from pymatgen.analysis.structure_matcher.StructureMatcher import fit [as 别名]
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]))
self.struct_list[1].apply_operation(op)
self.assertTrue(sm.fit(self.struct_list[0], self.struct_list[1]))
#Test failure under large atomic translation
self.struct_list[1].translate_sites([0], [.4, .4, .2],
frac_coords=True)
self.assertFalse(sm.fit(self.struct_list[0], self.struct_list[1]))
self.struct_list[1].translate_sites([0], [-.4, -.4, -.2],
frac_coords=True)
# random.shuffle(editor._sites)
self.assertTrue(sm.fit(self.struct_list[0], self.struct_list[1]))
#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)
示例15: test_occupancy_comparator
# 需要导入模块: from pymatgen.analysis.structure_matcher import StructureMatcher [as 别名]
# 或者: from pymatgen.analysis.structure_matcher.StructureMatcher import fit [as 别名]
def test_occupancy_comparator(self):
lp = Lattice.orthorhombic(10, 20, 30)
pcoords = [[0, 0, 0],
[0.5, 0.5, 0.5]]
s1 = Structure(lp, [{'Na': 0.6, 'K': 0.4}, 'Cl'], pcoords)
s2 = Structure(lp, [{'Xa': 0.4, 'Xb': 0.6}, 'Cl'], pcoords)
s3 = Structure(lp, [{'Xa': 0.5, 'Xb': 0.5}, 'Cl'], pcoords)
sm_sites = StructureMatcher(ltol=0.2, stol=0.3, angle_tol=5,
primitive_cell=False, scale=True,
attempt_supercell=True,
allow_subset=True,
supercell_size='num_sites',
comparator=OccupancyComparator())
self.assertTrue(sm_sites.fit(s1, s2))
self.assertFalse(sm_sites.fit(s1, s3))