def run_task(self, fw_spec):
        db = SPStructuresMongoAdapter.auto_load()
        tstructs = []
        species = fw_spec['species']
        t = fw_spec['threshold']
        for p in SubstitutionPredictor(threshold=t).list_prediction(species):
            subs = p['substitutions']
            if len(set(subs.values())) < len(species):
                continue
            st = SubstitutionTransformation(subs)
            target = map(str, subs.keys())
            for snl in db.get_snls(target):
                ts = TransformedStructure.from_snl(snl)
                ts.append_transformation(st)
                if ts.final_structure.charge == 0:
                    tstructs.append(ts)

        transmuter = StandardTransmuter(tstructs)
        f = RemoveDuplicatesFilter(structure_matcher=StructureMatcher(
            comparator=ElementComparator(), primitive_cell=False))
        transmuter.apply_filter(f)
        results = []
        for ts in transmuter.transformed_structures:
            results.append(ts.to_snl([]).to_dict)
        submissions = SPSubmissionsMongoAdapter.auto_load()
        submissions.insert_results(fw_spec['submission_id'], results)
 def __init__(self, threshold=1e-2, **kwargs):
     """
     Args:
         kwargs:
             args for SubstitutionProbability class
             lambda_table, alpha
     """
     self._kwargs = kwargs
     self._threshold = threshold
     self._substitutor = SubstitutionPredictor(threshold=threshold,
                                               **kwargs)
Beispiel #3
0
    def test_prediction(self):
        sp = SubstitutionPredictor(threshold = 8e-3)
        result = sp.list_prediction(['Na+', 'Cl-'], to_this_composition = True)[5]
        cprob = sp.p.cond_prob_list(result['substitutions'].keys(),
                                    result['substitutions'].values())
        self.assertAlmostEqual(result['probability'], cprob)
        self.assertEqual(set(result['substitutions'].values()), set(['Na+', 'Cl-']))

        result = sp.list_prediction(['Na+', 'Cl-'], to_this_composition = False)[5]
        cprob = sp.p.cond_prob_list(result['substitutions'].keys(),
                                    result['substitutions'].values())
        self.assertAlmostEqual(result['probability'], cprob)
        self.assertNotEqual(set(result['substitutions'].values()),
                            set(['Na+', 'Cl-']))

        c = Composition({'Ag2+' : 1, 'Cl-' : 2})
        result = sp.composition_prediction(c, to_this_composition = True)[2]
        self.assertEqual(set(result['substitutions'].values()), set(c.elements))
        result = sp.composition_prediction(c, to_this_composition = False)[2]
        self.assertEqual(set(result['substitutions'].keys()), set(c.elements))
Beispiel #4
0
 def __init__(self, threshold=1e-2, **kwargs):
     self.kwargs = kwargs
     self.threshold = threshold
     self._substitutor = SubstitutionPredictor(threshold=threshold,
                                               **kwargs)