def expand(names): """Expand ranges like H-Li to H, He and Li.""" i = 0 while i < len(names): name = names[i] if name.count("-") == 1: s1, s2 = name.split("-") Z1 = atomic_numbers.get(s1) Z2 = atomic_numbers.get(s2) if Z1 is not None and Z2 is not None: names[i : i + 1] = chemical_symbols[Z1 : Z2 + 1] i += Z2 - Z1 i += 1
def expand(self, names): """Expand ranges like H-Li to H, He, Li.""" if isinstance(names, str): names = [names] newnames = [] for name in names: if name.count('-') == 1: s1, s2 = name.split('-') Z1 = atomic_numbers.get(s1) Z2 = atomic_numbers.get(s2) if Z1 is None or Z2 is None: newnames.append(name) else: newnames.extend(chemical_symbols[Z1:Z2 + 1]) else: newnames.append(name) return newnames
def con_2_ase(path, boundary = [1,1,1]): if not path.endswith('.con'): path += '.con' f = open(path, 'r') ## seed to random f.readline() ## time stuff f.readline() basis_vec = map(float, f.readline().split()) angle_basis_vec = map(lambda x: x - 90 < _floatErr, map(float, f.readline().split())) if not np.array(angle_basis_vec).sum(): print "Only orthogonal lattice vectores are accepted!" return f.readline() f.readline() nrComponents = int(f.readline().strip()) nrAtomsPrType = np.array(map(int, f.readline().split())) #Masses, skiped in original parser. Same here f.readline() #All data is parced into these arrays before Atoms object is created. pos = np.zeros((nrAtomsPrType.sum(), 3)) atomNumbers = np.zeros(nrAtomsPrType.sum()) filt = np.zeros(nrAtomsPrType.sum(), dtype='int32') # for comp in xrange(nrComponents): element = f.readline().strip() if element.isdigit(): element = int(element) else: element = atomic_numbers.get(element) or self._unkownElement(element) f.readline() for i in xrange(nrAtomsPrType[0:comp].sum(), nrAtomsPrType[0:comp+1].sum()): data = f.readline().split() pos[i] = map(float, data[:3]) atomNumbers[i] = element filt[i] = int(data[3]) f.close() return (ase.Atoms(numbers=atomNumbers, positions=pos, cell=basis_vec, pbc=boundary), abs(filt-1))
def get_positions_from_block(keyword): # %Coordinates or %ReducedCoordinates -> atomic numbers, positions. block = kwargs.pop(keyword) positions = [] numbers = [] tags = [] types = {} for row in block: assert len(row) in [ndims + 1, ndims + 2] row = row[:ndims + 1] sym = row[0] assert sym.startswith('"') or sym.startswith("'") assert sym[0] == sym[-1] sym = sym[1:-1] pos0 = np.zeros(3) ndim = int(kwargs.get('dimensions', 3)) pos0[:ndim] = [float(element) for element in row[1:]] number = atomic_numbers.get(sym) # Use 0 ~ 'X' for unknown? tag = 0 if number is None: if sym not in types: tag = len(types) + 1 types[sym] = tag number = 0 tag = types[sym] tags.append(tag) numbers.append(number) positions.append(pos0) positions = np.array(positions) tags = np.array(tags, int) if types: ase_types = {} for sym, tag in types.items(): ase_types[('X', tag)] = sym info = {'types': ase_types} # 'info' dict for Atoms object else: tags = None info = None return numbers, positions, tags, info
def parse(self, content): #the output for atomic coords depends on whether we are doing an optimisation (single point calcs take the form 'atom, flag, x, y ,z' rather than simply 'atom, x, y, z' opt = 'opt' in content from ase.data import atomic_numbers self.data = [] temp_items = content.split(PARA_START) seq_count = 0 for i in temp_items: i=i.replace("\n ", "") if i.endswith(PARA_END): i = i.replace(PARA_END, "") i = i.split(FIELD_SEPARATOR) new_dict = {} self.data.append(new_dict) new_dict["Sequence number"] = seq_count seq_count += 1 for pos in range(len(names)): if names[pos]!="": new_dict[names[pos]] = self.auto_type(i[pos]) chm = i[charge_multiplicity].split(",") new_dict["Charge"] = int(chm[0]) new_dict["Multiplicity"] = int(chm[1]) #Read atoms atoms = [] positions = [] position = charge_multiplicity+1 if not opt: atom_flags = [] while position<len(i) and i[position]!="": s = i[position].split(",") atoms.append(atomic_numbers.get(s[0], 0)) positions.append([float(s[-3]), float(s[-2]), float(s[-1])]) position = position + 1 atom_flags.append(int(s[1])) new_dict["Atom_flags"]=atom_flags new_dict["Atomic_numbers"]=atoms new_dict["Positions"]=positions else: while position<len(i) and i[position]!="": s = i[position].split(",") atoms.append(atomic_numbers.get(s[0], 0)) positions.append([float(s[-3]), float(s[-2]), float(s[-1])]) position = position + 1 new_dict["Atomic_numbers"]=atoms new_dict["Positions"]=positions #read orbital swaps orb_swaps = [] if 'alter' in new_dict.get('Root',""): position +=1 while position<len(i) and i[position]!="": s = i[position].split(",") orb_swaps.append(s) position+=1 new_dict["Orbital_swaps"]=orb_swaps #Read more variables position +=1 while position<len(i) and i[position]!="": s = i[position].split("=") if len(s)==2: new_dict[s[0]]=self.auto_type(s[1]) else: print "Warning: unexpected input ",s position = position + 1