def _dataIndex(self, index): """ Return dataIndex (integer for index of _data) index can either be integer index for _data (fast) or string with atomic symbol (slow, order(len(_data))) """ if ( type(index) == int): dataIndex = index elif ( type(index) == str): inList,dataIndex = F.findInList(index, self._data["elements"]["name"]) if (not inList): raise RuntimeError("element is not present") else: raise RuntimeError("requires integer or string argument") return dataIndex
def _dataIndex(self, index): """ Return dataIndex (integer for index of _data) index can either be integer index for _data (fast) or string with atomic symbol (slow, order(len(_data))) """ if (type(index) == int): dataIndex = index elif (type(index) == str): inList, dataIndex = F.findInList(index, self._data["elements"]["name"]) if (not inList): raise RuntimeError("element is not present") else: raise RuntimeError("requires integer or string argument") return dataIndex
def addElement(self, elementName, elementMols): """Add an element to the glass""" # raise exceptions if (elementMols <= 0): raise RuntimeError("elementMols must be positive") atoms = PT.formula(elementName).atoms if (len(atoms) != 1): raise RuntimeError("elementName must have only one atom") for i in atoms: if (atoms[i] != 1): raise RuntimeError("elementName must have only one atom") # determine if added element is new or already exists nameList = self._data["elements"]["name"] inList,index = F.findInList(elementName, nameList) if (inList): self._data["elements"]["mols"][index] += elementMols else: molecularWeight = PT.elements.symbol(elementName).mass self._data["elements"]["name"].append(elementName) self._data["elements"]["mols"].append(float(elementMols)) self._data["elements"]["MW"].append(molecularWeight) self._checkSizes()
def addElement(self, elementName, elementMols): """Add an element to the glass""" # raise exceptions if (elementMols <= 0): raise RuntimeError("elementMols must be positive") atoms = PT.formula(elementName).atoms if (len(atoms) != 1): raise RuntimeError("elementName must have only one atom") for i in atoms: if (atoms[i] != 1): raise RuntimeError("elementName must have only one atom") # determine if added element is new or already exists nameList = self._data["elements"]["name"] inList, index = F.findInList(elementName, nameList) if (inList): self._data["elements"]["mols"][index] += elementMols else: molecularWeight = PT.elements.symbol(elementName).mass self._data["elements"]["name"].append(elementName) self._data["elements"]["mols"].append(float(elementMols)) self._data["elements"]["MW"].append(molecularWeight) self._checkSizes()