def __add__(self, other) -> "MullikenContribution": l = "".join(set([self.l, other.l])) d = self.contribution + other.contribution s1 = string2symbols(self.symbol) s2 = string2symbols(other.symbol) s = Formula.from_list(s1 + s2).format("reduce") return MullikenContribution(s, d, l)
def __add__(self, other) -> "DOSContribution": assert (self.values.shape == other.values.shape ), "DOS contributions shape does not match for addition." d = self.values + other.values l = "".join(set([self.l, other.l])) s1 = string2symbols(self.symbol) s2 = string2symbols(other.symbol) s = Formula.from_list(s1 + s2).format("reduce").format("metal") return DOSContribution(s, d, l)
def set_symbol(self, symbol): assert type(symbol) == str, "Symbol must be a string." try: s = string2symbols(symbol) except Exception as expt: raise Exception( "String could not be interpreted as atomic symbols.") assert all(k in chemical_symbols for k in s), "Symbol is not an element from the PSE." s = Formula.from_list(s).format("reduce").format("metal") self._symbol = s
def get_struct_id(self, universal=False): """ Get the id for the structure. If a struct_id has already been stored, this will be returned. Otherwise, a universal struct_id will be constructed. If universal argument is True, then the current struct_id will be discarded and a universal struct_id will be constructed. """ if len(self.struct_id) > 0 and universal == False: return self.struct_id else: ## Get type name = "" if len(self.get_lattice_vectors_better()) > 0: name = "Structure" else: name = "Molecule" ## Get formula formula = Formula.from_list(self.geometry["element"]) ## Reduce formula, which returns formula object formula = formula.format("hill") ## Then get string representation stored in formula._formula formula = str(formula) ## Add formula to name name += "_{}".format(formula) ## Add Date today = datetime.date.today() name += "_{}{}{}".format(today.year, today.month, today.year) ## Add random string name += "_{}".format(rand_str(10)) self.struct_id = name return self.struct_id
def formula(self): """Formula object.""" return Formula.from_list([chemical_symbols[Z] for Z in self.numbers])
def __sub__(self, other): l = "".join(set([self.l, other.l])) d = self.contribution - other.contribution s = Formula.from_list([self.symbol, other.symbol]).format("reduce") s = "$\Delta$" + s return MullikenContribution(s, d, l)
def formula(self) -> Formula: """Formula object.""" string = Formula.from_list(self).format('reduce') return Formula(string)