コード例 #1
0
ファイル: comparisons.py プロジェクト: zooks97/structureREST
def matminer_comparisons(structures,
                         preset='cn',
                         crystal_site_args={},
                         site_stats_args={},
                         distance_tol=0.01):
    '''
    Distance based on crystal sites implmented by matminer
    Args:
        structures ([dict]): dictionary-encoded pymatgen Structure objects
        preset (str): ['cn', 'ops'] CrystalNNFingerprint preset
        crystal_site_args (dict): **kwargs passed to CrysatlSiteFingerprint
        site_stats_args (dict): **kwargs passed to SiteStatsFingerprint
        distance_tol (float): distance below which comparison will return True
    Returns:
        [bool]: comparisons between each pair of structures; goes like
            [1-2, 1-3, ..., 1-n, 2-3, 2-4, ..., 2-n, ...]
    '''
    v = fingerprints.matminer_fingerprints(structures,
                                           preset=preset,
                                           crystal_site_args=crystal_site_args,
                                           site_stats_args=site_stats_args)
    distances = np.zeros((len(v), len(v)))
    for i in range(len(v)):
        for j in range(i, len(v)):
            distance = np.linalg.norm(np.array(v[i]) - np.array(v[j]))
            if distance <= distance_tol:
                distance = 0.
            distances[i, j] = (not bool(distance))
            distances[j, i] = distances[i, j]
    return distances.tolist()
コード例 #2
0
def matminer_distances(structures,
                       preset='cn',
                       crystal_site_args={},
                       site_stats_args={},
                       distance_tol=1.e-6):
    '''
    Distance based on crystal sites implmented by matminer
    Args:
        structures ([dict]): dictionary-encoded pymatgen Structure objects
        preset (str): ['cn', 'ops'] CrystalNNFingerprint preset
        crystal_site_args (dict): **kwargs passed to CrysatlSiteFingerprint
        site_stats_args (dict): **kwargs passed to SiteStatsFingerprint
        distance_tol (float): distance below which distance will be rounded to 0
    Returns:
        [float]: distances between each pair of structures; goes like
            [1-2, 1-3, ..., 1-n, 2-3, 2-4, ..., 2-n, ...]
    '''
    # structures = [Structure.from_dict(structure)
    #               for structure in structures]
    v = fingerprints.matminer_fingerprints(structures,
                                           preset=preset,
                                           crystal_site_args=crystal_site_args,
                                           site_stats_args=site_stats_args)
    distances = []
    for i, v_1 in enumerate(v):
        for j, v_2 in enumerate(v[i:]):
            if i != j + i:
                distance = np.linalg.norm(np.array(v_1) - np.array(v_2))
                if distance <= distance_tol:
                    distance = 0.
                distances.append(distance)
    return distances
コード例 #3
0
    def get(self):
        parser = flask_restful.reqparse.RequestParser()
        argument_names = [
            'structures', 'preset', 'crystal_site_args', 'site_stats_args'
        ]
        for argument_name in argument_names:
            parser.add_argument(ARGUMENTS[argument_name])
        args = parser.parse_args(strict=True)
        args['structures'] = flask.json.loads(args['structures'])
        calculated_fingerprints = fingerprints.matminer_fingerprints(**args)

        return flask.jsonify(calculated_fingerprints)
コード例 #4
0
                structures.append(material['structure'])
                document = {'source_id': material['_id'],
                            'soruce_collection': INPUT_COLLECTION,
                            'matminer_fingerprint': None,
                            'stidy_fingerprint': None}
                documents.append(document)
            except Exception as e:
                logging.error('source_id: {} {}'.format(material['_id'], e))
        else:
            logging.error('Too large, {} atoms {}'.format(
                len(structure.sites), material['_id']))
    else:
        logging.error('Unordered {}'.format(material['_id']))

logging.info('Calcluating matminer fingerprints')
matminer_fingerprints = fingerprints.matminer_fingerprints(structures)
logging.info('Adding fingerprints to documents')
matminer_documents = documents.copy()
for d, document in enumerate(matminer_documents):
     matminer_documents[d]['matminer_fingerprint'] = matminer_fingerprints[d]
logging.info('inserting {} documents into {}'.format(
    len(documents), 'matminer'))
result = matminer_collection.insert_many(documents)
logging.info('inserted {} documents'.format(len(result.inserted_ids)))

logging.info('Calculating STRUCTURE TIDY fingerprints')
stidy_fingerprints = fingerprints.stidy_fingerprints(structures)
logging.info('Adding fingerprints to documents')
stidy_documents = documents.copy()
for d, document in enumerate(stidy_documents):
     stidy_documents[d]['stidy_fingerprint'] = stidy_fingerprints[d]