def CalcCompoundDescriptorsForComposition(self, compos='', composList=None, propDict={}): """ calculates all simple descriptors for a given composition **Arguments** - compos: a string representation of the composition - composList: a *composVect* - propDict: a dictionary containing the properties of the composition as a whole (e.g. structural variables, etc.) The client must provide either _compos_ or _composList_. If both are provided, _composList_ takes priority. **Returns** the list of descriptor values **Notes** - when _compos_ is provided, this uses _chemutils.SplitComposition_ to split the composition into its individual pieces """ if composList is None: composList = chemutils.SplitComposition(compos) res = [] for cl in self.compoundList: val = Parser.CalcSingleCompoundDescriptor(composList, cl[1:], self.atomDict, propDict) res.append(val) return res
def CalcDescriptorsForComposition(self, composVect, propDict): """ calculates all descriptors for a given composition **Arguments** - compos: a string representation of the composition - propDict: a dictionary containing the properties of the composition as a whole (e.g. structural variables, etc.). These are used to generate Compound Descriptors **Returns** the list of all descriptor values **Notes** - this uses _chemutils.SplitComposition_ to split the composition into its individual pieces """ composList = chemutils.SplitComposition(composVect[0]) try: r1 = self.CalcSimpleDescriptorsForComposition( composList=composList) except KeyError: res = [] else: r2 = self.CalcCompoundDescriptorsForComposition( composList=composList, propDict=propDict) res = r1 + r2 return tuple(res)
def test_chemutils(self): self.assertEqual(chemutils.SplitComposition('Fe'), [('Fe', 1)]) self.assertEqual(chemutils.SplitComposition('Fe3Al'), [('Fe', 3.0), ('Al', 1)]) self.assertEqual(chemutils.SplitComposition('Fe99PdAl'), [('Fe', 99.0), ('Pd', 1), ('Al', 1)]) self.assertEqual(chemutils.SplitComposition('TiNiSiSO12P'), [('Ti', 1), ('Ni', 1), ('Si', 1), ('S', 1), ('O', 12.0), ('P', 1)]) temp = [ '[Xe] 4f^12 6s^2', '[Xe] 4f^14 5d^6 6s^2', '[Xe] 4f^14 5d^10 6s^2', '[Xe] 4f^14 5d^10 6s^2 6p^1', '[Xe] 5d^10' ] for entry, expected in zip(temp, (14, 8, 2, 3, 10)): self.assertEqual( chemutils.ConfigToNumElectrons(entry, ignoreFullD=True, ignoreFullF=True), expected) for entry, expected in zip(temp, (14, 8, 12, 13, 10)): self.assertEqual( chemutils.ConfigToNumElectrons(entry, ignoreFullD=False, ignoreFullF=True), expected) for entry, expected in zip(temp, (14, 22, 16, 17, 10)): self.assertEqual( chemutils.ConfigToNumElectrons(entry, ignoreFullD=True, ignoreFullF=False), expected) for entry, expected in zip(temp, (14, 22, 26, 27, 10)): self.assertEqual( chemutils.ConfigToNumElectrons(entry, ignoreFullD=False, ignoreFullF=False), expected)
def CalcSimpleDescriptorsForComposition(self, compos='', composList=None): """ calculates all simple descriptors for a given composition **Arguments** - compos: a string representation of the composition - composList: a *composVect* The client must provide either _compos_ or _composList_. If both are provided, _composList_ takes priority. **Returns** the list of descriptor values **Notes** - when _compos_ is provided, this uses _chemutils.SplitComposition_ to split the composition into its individual pieces - if problems are encountered because of either an unknown descriptor or atom type, a _KeyError_ will be raised. """ if composList is None: composList = chemutils.SplitComposition(compos) try: res = [] for i in xrange(len(self.simpleList)): descName, targets = self.simpleList[i] for target in targets: try: method = getattr(self, target) except AttributeError: print('Method %s does not exist' % (target)) else: res.append(method(descName, composList)) except KeyError as msg: print('composition %s caused problems' % composList) raise KeyError(msg) return res