Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Production Updates #65

Merged
merged 93 commits into from
Oct 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
4d20b59
Group based on total mag rather than magmoms
shyamd Jul 20, 2018
ec06753
convert to conventional standard
shyamd Jul 20, 2018
42ccbf8
Clean up quotes
shyamd Jul 20, 2018
7ea3325
import bumpy
shyamd Jul 20, 2018
30f98fe
Only normalize magnetization once
shyamd Jul 20, 2018
fea236f
wrap all SNL construction in try/except
shyamd Jul 21, 2018
8f801d3
Merge branch 'master' into updates
shyamd Aug 29, 2018
fc39262
Track structure for dielectric calc
shyamd Aug 29, 2018
6e9781e
Update electronic_structure
shyamd Aug 31, 2018
10d0563
allow for no parameters dict
shyamd Aug 31, 2018
9086447
Import load_settings
shyamd Aug 31, 2018
a5d2efb
Update maggma call
shyamd Aug 31, 2018
831fdd2
Merge branch 'master' into updates
shyamd Aug 31, 2018
13ad542
symprec for all CIFWriters
shyamd Aug 31, 2018
a7c6752
Use structure from dielectric document
shyamd Sep 9, 2018
8e812a6
Merge branch 'master' into updates
shyamd Sep 10, 2018
c4a569b
Merge remote-tracking branch 'origin/master' into updates
shyamd Sep 10, 2018
747f082
Change substrate settings to json
shyamd Sep 11, 2018
ad51dc8
fix substrates builder
shyamd Sep 11, 2018
5e5e0e9
Remove collinear for materials builder
shyamd Sep 14, 2018
e985852
Merge branch 'master' into updates
shyamd Sep 17, 2018
f80dc35
Add diffraction unit test
shyamd Sep 20, 2018
ef8defd
switch diffraction builder to be based on MapBuilder
shyamd Sep 20, 2018
7da6be7
Fix bug in electronic structure plotter
shyamd Sep 20, 2018
fce2299
Finish conversion to Mapbuilder
shyamd Sep 21, 2018
52d6684
Add created_at
shyamd Sep 25, 2018
4ce8491
switch material’s structure to conventional standard
shyamd Sep 25, 2018
86468a8
Add created_at to website doc
shyamd Sep 25, 2018
e7d1af5
fix created_at
shyamd Sep 25, 2018
cf1f4a3
Cleanup for diffraction builders
shyamd Sep 26, 2018
ecfc9ff
fix bug errors during thermo build
shyamd Sep 26, 2018
53a2c5d
Fix task_tagger test
shyamd Sep 26, 2018
41965b7
Fix referencing empty keys
shyamd Sep 26, 2018
0e70525
fix test making random files
shyamd Sep 26, 2018
611d6ce
Codacy cleanup
shyamd Sep 26, 2018
d8ea298
Fix accidental comma delete
shyamd Sep 26, 2018
e1b9aa8
Silly fixes for pybtex spam
shyamd Sep 26, 2018
6782b1b
Ensure greater than 0 bandgap
shyamd Sep 27, 2018
258b21d
Merge branch 'master' into updates
shyamd Oct 1, 2018
cdc5ba0
Fix bad query and clean up
shyamd Oct 2, 2018
dcc23d5
Restore to calculated structure
shyamd Oct 2, 2018
9503907
clean up style
shyamd Oct 2, 2018
d3053a2
Fix case problem with detecting METAGGA
shyamd Oct 2, 2018
cba81fd
Convert to MapBuilder
shyamd Oct 2, 2018
33968a1
Switch to MapBuilder
shyamd Oct 3, 2018
42ebff6
clean up descriptors
shyamd Oct 3, 2018
2639ec8
Move schema to json
shyamd Oct 3, 2018
315f25e
More schema to json
shyamd Oct 3, 2018
d5f37da
More schema to json
shyamd Oct 3, 2018
7ef4d94
convert to MapBuilder
shyamd Oct 3, 2018
41fcf46
Remove empty file
shyamd Oct 3, 2018
3b5cef1
more clean up
shyamd Oct 3, 2018
8d5035d
Fix query bug
shyamd Oct 3, 2018
53d3c1a
Revert update to MapBuilder
shyamd Oct 3, 2018
cc3b6c2
Fix schema loading
shyamd Oct 3, 2018
03b3faa
Update bond valence schema
mkhorton Oct 3, 2018
77ec2f4
Fix bug with spglib and not returning good structures
shyamd Oct 8, 2018
d6301d6
preserve thermo values in new collection
shyamd Oct 8, 2018
98fe938
Bug referencing wrong components
shyamd Oct 8, 2018
c8ce4ff
remove lu_field after move to MapBuilder
shyamd Oct 8, 2018
432402b
Update magnetic grouping
mkhorton Oct 15, 2018
c6260aa
Fix missing comma
shyamd Oct 18, 2018
b0bf3e9
Keep magmoms for magnetism
shyamd Oct 18, 2018
6d58fba
Move settings to json
shyamd Oct 18, 2018
37a6370
convert to MapBuilder
shyamd Oct 18, 2018
a621f92
Single calc function
shyamd Oct 18, 2018
2403ef3
Update for new conversion dict. Reduce complexity
shyamd Oct 18, 2018
0909182
Reorder snl and mat querying since materials are guaranteed to exist …
shyamd Oct 18, 2018
e36666f
Merge pull request #67 from materialsproject/magnetic-grouping-update
shyamd Oct 19, 2018
3f185b4
Add warnings
shyamd Oct 19, 2018
660d1c3
remove task_id from auto copy
shyamd Oct 20, 2018
29c58a6
Fix some imports
shyamd Oct 20, 2018
35f9da5
refactor back to regular builder
shyamd Oct 20, 2018
38ec093
Get items and smash docs together
shyamd Oct 20, 2018
bacf301
lots of little processing fixes
shyamd Oct 20, 2018
34b7f91
Code cleanup
shyamd Oct 24, 2018
0fd5f53
remove duplicate key
shyamd Oct 24, 2018
3f0d5b6
Fix empty warnings
shyamd Oct 24, 2018
64452dd
handle errors better
shyamd Oct 24, 2018
4d7a03f
Switch key name to symmetry
shyamd Oct 24, 2018
c979a85
Revert to incorrect energy in root doc
shyamd Oct 26, 2018
a10ecf3
Remove viewer for now
shyamd Oct 26, 2018
4a3d05e
Typo
shyamd Oct 26, 2018
fdad6b2
use max rather than sort
shyamd Oct 26, 2018
42b9a75
Clean up formatting
shyamd Oct 26, 2018
6174d1a
Better logging and less cryptic code
shyamd Oct 26, 2018
06898db
Better discriminator for None
shyamd Oct 26, 2018
96a44cf
post_process has fields for now
shyamd Oct 26, 2018
10e5a72
Fix mag_types
shyamd Oct 26, 2018
4fa2d3f
Fix a bug in dielectric builder
shyamd Oct 30, 2018
9fa4865
copy over total_magnetism
shyamd Oct 30, 2018
2c6612d
Improved schema
shyamd Oct 30, 2018
b92b453
Actually validate
shyamd Oct 30, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion emmet/abinit/phonon.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def get_items(self):
# All relevant materials that have been updated since diffraction props were last calculated
q = dict(self.query)
q.update(self.materials.lu_filter(self.phonon))
mats = list(self.materials().find(q, {"mp_id": 1}))
mats = list(self.materials.find(q, {"mp_id": 1}))
self.logger.info("Found {} new materials for phonon data".format(len(mats)))

# list of properties queried from the results DB
Expand Down
141 changes: 32 additions & 109 deletions emmet/materials/basic_descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# 1) Add checking OPs present in current implementation of site fingerprints.
# 2) Complete documentation!!!

from maggma.builder import Builder
from maggma.examples.builders import MapBuilder

__author__ = "Nils E. R. Zimmermann <nerz@lbl.gov>"

Expand All @@ -20,9 +20,9 @@
"EconNN"]


class BasicDescriptorsBuilder(Builder):
class BasicDescriptorsBuilder(MapBuilder):

def __init__(self, materials, descriptors, mat_query=None, **kwargs):
def __init__(self, materials, descriptors, **kwargs):
"""
Calculates site-based descriptors (e.g., coordination numbers
with different near-neighbor finding approaches) for materials and
Expand All @@ -44,97 +44,35 @@ def __init__(self, materials, descriptors, mat_query=None, **kwargs):

self.materials = materials
self.descriptors = descriptors
self.mat_query = mat_query if mat_query else {}

# Set up all targeted site descriptors.
self.sds = {}
for nn in nn_target_classes:
nn_ = getattr(local_env, nn)
k = 'cn_{}'.format(nn)
self.sds[k] = CoordinationNumber(nn_(), use_weights='none')
k = 'cn_wt_{}'.format(nn)
self.sds[k] = CoordinationNumber(nn_(), use_weights='sum')
self.all_output_pieces = {'site_descriptors': [k for k in self.sds.keys()]}
self.sds['csf'] = CrystalNNFingerprint.from_preset('ops',
k = "cn_{}".format(nn)
self.sds[k] = CoordinationNumber(nn_(), use_weights="none")
k = "cn_wt_{}".format(nn)
self.sds[k] = CoordinationNumber(nn_(), use_weights="sum")
self.all_output_pieces = {"site_descriptors": [k for k in self.sds.keys()]}
self.sds["csf"] = CrystalNNFingerprint.from_preset("ops",
distance_cutoffs=None,
x_diff_weight=None)
self.all_output_pieces['statistics'] = ['csf']
self.all_output_pieces["statistics"] = ["csf"]

# Set up all targeted composition descriptors.
self.cds = {}
self.cds["magpie"] = ElementProperty.from_preset('magpie')
self.all_output_pieces['composition_descriptors'] = ['magpie']
self.cds["magpie"] = ElementProperty.from_preset("magpie")
self.all_output_pieces["composition_descriptors"] = ["magpie"]

self.all_output_pieces['meta'] = ['atomate']
self.all_output_pieces["meta"] = ["atomate"]

super().__init__(sources=[materials],
targets=[descriptors],
super().__init__(source=materials,
target=descriptors,
ufn=self.calc,
projection=["structure"],
**kwargs)

def get_items(self):
"""
Gets all materials that need new descriptors.
For example, entirely new materials and materials
for which certain descriptor in the current Store
are still missing.

Returns:
generator of materials to calculate basic descriptors
and of the target quantities to be calculated
(e.g., CN with the minimum distance near neighbor
(MinimumDistanceNN) finding class from pymatgen which has label
"cn_mdnn").
"""

self.logger.info("Basic-Descriptors Builder Started")

self.logger.info("Setting indexes")

# All relevant materials that have been updated since descriptors
# were last calculated

q = dict(self.mat_query)
all_task_ids = list(self.materials.distinct(self.materials.key, q))
q.update(self.materials.lu_filter(self.descriptors))
new_task_ids = list(self.materials.distinct(self.materials.key, q))
self.logger.info(
"Found {} entirely new materials for descriptors data".format(
len(new_task_ids)))
for task_id in all_task_ids:
if task_id in new_task_ids:
any_piece = True

else: # Any piece of info missing?
data_present = self.descriptors.query(
properties=[self.descriptors.key,
"meta",
"composition_descriptors",
"site_descriptors",
"statistics"],
criteria={self.descriptors.key: task_id}).limit(1)[0]
any_piece = False
for k, v in self.all_output_pieces.items():
if k not in list(data_present.keys()):
any_piece = True
break
else:
any_piece = False
for e in v:
if e not in data_present[k]:
any_piece = True
break
if not any_piece:
for l in self.sds['csf'].feature_labels():
for fpi in data_present['site_descriptors']['csf']:
if l not in fpi.keys():
any_piece = True
break
if any_piece:
yield self.materials.query(
properties=[self.materials.key, "structure"],
criteria={self.materials.key: task_id}).limit(1)[0]

def process_item(self, item):
def calc(self, item):
"""
Calculates all basic descriptors for the structures

Expand All @@ -148,45 +86,30 @@ def process_item(self, item):
self.logger.debug("Calculating basic descriptors for {}".format(
item[self.materials.key]))

struct = Structure.from_dict(item['structure'])
struct = Structure.from_dict(item["structure"])

descr_doc = {'structure': struct.copy()}
descr_doc['meta'] = {'atomate': get_meta_from_structure(struct)}
descr_doc = {"structure": struct.copy()}
descr_doc["meta"] = {"atomate": get_meta_from_structure(struct)}
try:
comp_descr = [{'name': 'magpie'}]
comp_descr = [{"name": "magpie"}]
labels = self.cds["magpie"].feature_labels()
values = self.cds["magpie"].featurize(struct.composition)
for label, value in zip(labels, values):
comp_descr[0][label] = value
descr_doc['composition_descriptors'] = comp_descr
descr_doc["composition_descriptors"] = comp_descr
except Exception as e:
self.logger.error("Failed getting Magpie descriptors: "
"{}".format(e))
descr_doc['site_descriptors'] = \
descr_doc["site_descriptors"] = \
self.get_site_descriptors_from_struct(
descr_doc['structure'])
descr_doc['statistics'] = \
descr_doc["structure"])
descr_doc["statistics"] = \
self.get_statistics(
descr_doc['site_descriptors'])
descr_doc["site_descriptors"])
descr_doc[self.descriptors.key] = item[self.materials.key]

return descr_doc

def update_targets(self, items):
"""
Inserts the new task_types into the task_types collection.

Args:
items ([[dict]]): a list of list of descriptors dictionaries to update.
"""
items = list(filter(None, items))

if len(items) > 0:
self.logger.info("Updating {} basic-descriptors docs".format(len(items)))
self.descriptors.update(docs=items)
else:
self.logger.info("No items to update")

def get_site_descriptors_from_struct(self, structure):
doc = {}

Expand All @@ -196,7 +119,7 @@ def get_site_descriptors_from_struct(self, structure):
d = []
l = sd.feature_labels()
for i, s in enumerate(structure.sites):
d.append({'site': i})
d.append({"site": i})
for j, desc in enumerate(sd.featurize(structure, i)):
d[i][l[j]] = desc
doc[k] = d
Expand All @@ -207,7 +130,7 @@ def get_site_descriptors_from_struct(self, structure):

return doc

def get_statistics(self, site_descr, fps=('csf', )):
def get_statistics(self, site_descr, fps=("csf", )):
doc = {}

# Compute site-descriptor statistics.
Expand All @@ -223,9 +146,9 @@ def get_statistics(self, site_descr, fps=('csf', )):
tmp[l].append(v)
d = []
for k, l in tmp.items():
dtmp = {'name': k}
dtmp['mean'] = np.mean(tmp[k])
dtmp['std'] = np.std(tmp[k])
dtmp = {"name": k}
dtmp["mean"] = np.mean(tmp[k])
dtmp["std"] = np.std(tmp[k])
d.append(dtmp)
doc[fp] = d

Expand Down
100 changes: 35 additions & 65 deletions emmet/materials/bond_valence.py
Original file line number Diff line number Diff line change
@@ -1,95 +1,65 @@
import os.path
from monty.serialization import loadfn

from pymatgen.core.structure import Structure
from pymatgen.analysis.bond_valence import BVAnalyzer
from pymatgen.core.periodic_table import Specie
from pymatgen import __version__ as pymatgen_version

from maggma.builder import Builder
from maggma.examples.builders import MapBuilder
from maggma.validator import JSONSchemaValidator


BOND_VALENCE_SCHEMA = {
"title": "bond_valence",
"type": "object",
"properties":
{
"task_id": {"type": "string"},
"method": {"type": "string"},
"possible_species": {"type": "array", "items": {"type": "strinig"}},
"possible_valences": {"type": "array", "items": {"type": "number"}},
"successful": {"type": "boolean"},
"pymatgen_version": {"type": "string"},
},
"required": ["task_id", "successful", "pymatgen_version"]
}
MODULE_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)))
BOND_VALENCE_SCHEMA = os.path.join(MODULE_DIR, "schema", "bond_valence.json")


class BondValenceBuilder(Builder):
class BondValenceBuilder(MapBuilder):
"""
Calculate plausible oxidation states from structures.
"""

def __init__(self, materials, bond_valence,
query=None, **kwargs):
def __init__(self, materials, bond_valence, **kwargs):

self.materials = materials
self.bond_valence = bond_valence
self.query = query or {}

super().__init__(sources=[materials],
targets=[bond_valence],
**kwargs)

def get_items(self):
self.bond_valence.validator = JSONSchemaValidator(loadfn(BOND_VALENCE_SCHEMA))
super().__init__(source=materials, target=bond_valence, ufn=self.calc, projection=["structure"], **kwargs)

materials = self.materials.query(criteria=self.query,
properties=["task_id", "structure"])
# All relevant materials that have been updated since bond valences
# were last calculated
q = dict(self.query)
q.update(self.materials.lu_filter(self.bond_valence))
new_keys = list(self.materials.distinct(self.materials.key, q))

materials = self.materials.query(criteria={self.materials.key: {'$in': new_keys}},
properties=["task_id", "structure"])

self.total = materials.count()
self.logger.info("Found {} new materials for bond valence analysis".format(self.total))
def calc(self, item):
s = Structure.from_dict(item['structure'])

for material in materials:
yield material
d = {"pymatgen_version": pymatgen_version, "successful": False}

def process_item(self, item):
s = Structure.from_dict(item['structure'])
try:
bva = BVAnalyzer()
valences = bva.get_valences(s)
possible_species = {str(Specie(s[idx].specie, oxidation_state=valence))
for idx, valence in enumerate(valences)}
possible_species = {
str(Specie(s[idx].specie, oxidation_state=valence)) for idx, valence in enumerate(valences)
}

method = "BVAnalyzer"

d["successful"] = True
d["bond_valence"] = {
"possible_species": list(possible_species),
"possible_valences": valences,
"method": "oxi_state_guesses"
}

except ValueError:
try:
first_oxi_state_guess = s.composition.oxi_state_guesses()[0]
valences = [first_oxi_state_guess[site.species_string] for site in s]
possible_species = {str(Specie(el, oxidation_state=valence))
for el, valence in first_oxi_state_guess.items()}
method = "oxi_state_guesses"
except:
return {
"task_id": item['task_id'],
"pymatgen_version": pymatgen_version,
"successful": False
possible_species = {
str(Specie(el, oxidation_state=valence)) for el, valence in first_oxi_state_guess.items()
}
d["successful"] = True
d["bond_valence"] = {
"possible_species": list(possible_species),
"possible_valences": valences,
"method": "oxi_state_guesses"
}
except:
pass

return {
"task_id": item['task_id'],
"possible_species": list(possible_species),
"possible_valences": valences,
"method": method,
"pymatgen_version": pymatgen_version,
"successful": True
}

def update_targets(self, items):
self.logger.debug("Updating {} bond valence documents".format(len(items)))
self.bond_valence.update(docs=items, key=['task_id'])
return d
Loading