def setUp(self): with open(os.path.join(test_dir, 'test_toec_data.json')) as f: self.data_dict = json.load(f) self.strains = [Strain(sm) for sm in self.data_dict['strains']] self.pk_stresses = [Stress(d) for d in self.data_dict['pk_stresses']] self.c2 = self.data_dict["C2_raw"] self.c3 = self.data_dict["C3_raw"] self.exp = ElasticTensorExpansion.from_voigt([self.c2, self.c3]) self.cu = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3.623), ["Cu"], [[0] * 3]) indices = [(0, 0), (0, 1), (3, 3)] values = [167.8, 113.5, 74.5] cu_c2 = ElasticTensor.from_values_indices(values, indices, structure=self.cu, populate=True) indices = [(0, 0, 0), (0, 0, 1), (0, 1, 2), (0, 3, 3), (0, 5, 5), (3, 4, 5)] values = [-1507., -965., -71., -7., -901., 45.] cu_c3 = Tensor.from_values_indices(values, indices, structure=self.cu, populate=True) self.exp_cu = ElasticTensorExpansion([cu_c2, cu_c3]) cu_c4 = Tensor.from_voigt(self.data_dict["Cu_fourth_order"]) self.exp_cu_4 = ElasticTensorExpansion([cu_c2, cu_c3, cu_c4]) warnings.simplefilter("ignore")
def setUp(self): with open(os.path.join(test_dir, 'test_toec_data.json')) as f: self.data_dict = json.load(f) self.strains = [Strain(sm) for sm in self.data_dict['strains']] self.pk_stresses = [Stress(d) for d in self.data_dict['pk_stresses']] self.c2 = self.data_dict["C2_raw"] self.c3 = self.data_dict["C3_raw"] self.exp = ElasticTensorExpansion.from_voigt([self.c2, self.c3]) self.cu = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3.623), ["Cu"], [[0]*3]) indices = [(0, 0), (0, 1), (3, 3)] values = [167.8, 113.5, 74.5] cu_c2 = ElasticTensor.from_values_indices(values, indices, structure=self.cu, populate=True) indices = [(0, 0, 0), (0, 0, 1), (0, 1, 2), (0, 3, 3), (0, 5, 5), (3, 4, 5)] values = [-1507., -965., -71., -7., -901., 45.] cu_c3 = Tensor.from_values_indices(values, indices, structure=self.cu, populate=True) self.exp_cu = ElasticTensorExpansion([cu_c2, cu_c3]) cu_c4 = Tensor.from_voigt(self.data_dict["Cu_fourth_order"]) self.exp_cu_4 = ElasticTensorExpansion([cu_c2, cu_c3, cu_c4]) warnings.simplefilter("ignore")
def test_init(self): cijkl = Tensor.from_voigt(self.c2) cijklmn = Tensor.from_voigt(self.c3) exp = ElasticTensorExpansion([cijkl, cijklmn]) from_voigt = ElasticTensorExpansion.from_voigt([self.c2, self.c3]) self.assertEqual(exp.order, 3)
def process_item(self, item): docs, material_dict = item grouped = group_by_material_id(material_dict, docs, 'input_structure') formula = docs[0]['pretty_formula'] if not grouped: formula = Structure.from_dict(list( material_dict.values())[0]).composition.reduced_formula logger.debug("No material match for {}".format(formula)) # For now just do the most recent one that's not failed # TODO: better sorting of docs all_docs = [] for task_id, elastic_docs in grouped.items(): elastic_docs = sorted(elastic_docs, key=lambda x: (x['order'], x['state'], x['completed_at'])) grouped_by_order = { k: list(v) for k, v in groupby(elastic_docs, key=lambda x: x['order']) } soec_docs = grouped_by_order.get(2) toec_docs = grouped_by_order.get(3) if soec_docs: final_doc = soec_docs[-1] else: final_doc = toec_docs[-1] structure = Structure.from_dict(final_doc['optimized_structure']) formula = structure.composition.reduced_formula elements = [s.symbol for s in structure.composition.elements] chemsys = '-'.join(elements) # Issue warning if relaxed structure differs warnings = final_doc.get('warnings') or [] opt = Structure.from_dict(final_doc['optimized_structure']) init = Structure.from_dict(final_doc['input_structure']) # TODO: are these the right params? if not StructureMatcher().fit(init, opt): warnings.append("Inequivalent optimization structure") material_mag = CollinearMagneticStructureAnalyzer( opt).ordering.value material_mag = mag_types[material_mag] if final_doc['magnetic_type'] != material_mag: warnings.append("Elastic magnetic phase is {}".format( final_doc['magnetic_type'])) warnings = warnings or None # Filter for failure and warnings k_vrh = final_doc['k_vrh'] if k_vrh < 0 or k_vrh > 600: state = 'failed' elif warnings is not None: state = 'warning' else: state = 'successful' final_doc.update({"warnings": warnings}) elastic_summary = { 'task_id': task_id, 'all_elastic_fits': elastic_docs, 'elasticity': final_doc, 'spacegroup': init.get_space_group_info()[0], 'magnetic_type': final_doc['magnetic_type'], 'pretty_formula': formula, 'chemsys': chemsys, 'elements': elements, 'last_updated': self.elasticity.lu_field, 'state': state } if toec_docs: # TODO: this should be a bit more refined final_toec_doc = deepcopy(toec_docs[-1]) et_exp = ElasticTensorExpansion.from_voigt( final_toec_doc['elastic_tensor_expansion']) symbol_dict = et_exp[1].zeroed(1e-2).get_symbol_dict() final_toec_doc.update({"symbol_dict": symbol_dict}) set_(elastic_summary, "elasticity.third_order", final_toec_doc) all_docs.append(jsanitize(elastic_summary)) # elastic_summary.update(final_doc) return all_docs
def test_init(self): cijkl = Tensor.from_voigt(self.c2) cijklmn = Tensor.from_voigt(self.c3) exp = ElasticTensorExpansion([cijkl, cijklmn]) from_voigt = ElasticTensorExpansion.from_voigt([self.c2, self.c3]) self.assertEqual(exp.order, 3)