Skip to content

Commit

Permalink
Updated ionic_mobility collection with new scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
dchannah committed Mar 20, 2017
1 parent 19a125c commit 4d77148
Show file tree
Hide file tree
Showing 5 changed files with 506 additions and 0 deletions.
1 change: 1 addition & 0 deletions ionic_mobility/analyze_db.py
Expand Up @@ -100,6 +100,7 @@ def build_db_query(criterion=None, value=None, ucq=None, custom=False):
return eval(ucq)

if __name__ == "__main__":
# A simple set of commands to test the script.
# Let's compare the minimum cation distance for the post-spinels.
path_id_cm = "mvc-6921-NEB-001"
path_id_cf = "mvc-12110-NEB-001"
Expand Down
Binary file added ionic_mobility/analyze_db.pyc
Binary file not shown.
45 changes: 45 additions & 0 deletions ionic_mobility/crm.py
@@ -0,0 +1,45 @@
import numpy as np
import scipy.cluster.vq as vq
from pylab import plot, show
from analyze_db import initialize_db, build_db_query, build_feature_vector

"""
Clustering-ranking-modeling to learn ionic mobility predictors. We're using
the X-means clustering algorithm here.
"""


def build_point_list(fv_dict):
"""build_point_list
Builds a list of feature vectors for clustering analysis.
:param fv_dict: Dictionary of all needed feature vectors.
:return: [feature vector 1, ..., feature vector N], with N total docs.
"""
point_list = []
for pid in fv_dict:
vector_columns = [fv_dict[pid][prop] for prop in fv_dict[pid]]
point_list.append(vector_columns)
return np.array(point_list)


if __name__ == "__main__":
# We need a list of properties for our feature vector.
feature_list = ['activation_energy', 'volume_per_anion',
'average_bond_length', 'min_cation_distance']

# We also need a database and some documents from it.
yaml_file = "/Users/dchannah/yaml/paper2.yaml"
coll = initialize_db(yaml_file)

# Let's just grab all of the documents in the ionic mobility DB for now.
docs = coll.find()

# Now we build our feature vector for all these docs.
fv = build_feature_vector(feature_list, docs)

# Now let's do some clustering.
points = build_point_list(fv)
points = vq.whiten(points) # Need to normalize each column first.
centroids, distortion = vq.kmeans(points, 4)
indices, _ = vq.vq(points, centroids)

Binary file added ionic_mobility/database_getter.pyc
Binary file not shown.

0 comments on commit 4d77148

Please sign in to comment.