def without_dummy_atoms(geo): """ return a copy of the geometry without dummy atoms """ syms = symbols(geo) non_dummy_idxs = [idx for idx, sym in enumerate(syms) if pt.to_Z(sym)] return from_subset(geo, non_dummy_idxs)
def to_number(atom): """ Obtain the atomic number for a given atom. :param atom: atom representation (symbol, number, mass) :type atom: str/int :rtype: int """ return periodictable.to_Z(atom)
def heavy_atom_count(gra, with_dummy=False): """ the number of heavy atoms """ if not with_dummy: gra = without_dummy_atoms(gra) atm_sym_dct = atom_symbols(gra) nhvy_atms = sum(pt.to_Z(sym) != 1 for sym in atm_sym_dct.values()) return nhvy_atms
def electron_count(fml): """ the number of atoms in this molecular formula """ assert _is_standard(fml) elec_count = 0 for key in fml: value = fml[key] elec_count += value*pt.to_Z(key) return elec_count
def without_dummy_atoms(geo): """ return a copy of the geometry without dummy atoms """ syms = symbols(geo) xyzs = coordinates(geo) non_dummy_keys = [idx for idx, sym in enumerate(syms) if pt.to_Z(sym)] syms = list(map(syms.__getitem__, non_dummy_keys)) xyzs = list(map(xyzs.__getitem__, non_dummy_keys)) return from_data(syms, xyzs)
def getATOMS(self, inlines): self.CHARGES = [] self.CARTESIANS = [] for i in range(0, len(inlines)): if inlines[i].find("ATOM") > -1 or inlines[i].find( "HETATM") > -1: self.CHARGES.append(float( (PT.to_Z(inlines[i].split()[2])))) self.CARTESIANS += [ float(coordinate) / AU_TO_ANG for coordinate in inlines[i].split()[4:7] ]
def _from_json(inp): with open(inp, "r") as j: data = json.load(j) charges = [PT.to_Z(atom) for atom in data["molecule"]["symbols"]] # reshape coordinates as (nat, 3) and convert to angstrom cartesians = [coordinate for coordinate in data["molecule"]["geometry"]] functional = data["model"]["method"] return cartesians, charges, functional
def add_element(fml, sym, num=1): """ add or subtract (if num < 0) this element from the molecular formula """ assert pt.to_Z(sym) assert _is_standard(fml) sym = pt.to_E(sym) fml = fml.copy() if sym in fml: fml[sym] += num else: fml[sym] = num assert fml[sym] > 0 return fml
def _encode_vertex_attributes(sym, imp_hyd_vlc, par): """ encode vertex attributes as an integer (or "color") scheme: atomic symbol <=> hundreds place, as atomic number implicit hydrogen valence <=> tens place parity <=> ones place (None->0, False->1, True->2) """ id3 = pt.to_Z(sym) id2 = imp_hyd_vlc id1 = 0 if par is None else 1 + int(par) color = id3 * 100 + id2 * 10 + id1 * 1 return color
def getCHARGES(self, inlines): self.CHARGES = [] for i in range(0, len(inlines)): if inlines[i].find("#") > -1: if len(inlines[i + 1].split()) == 0: start = i + 5 if len(inlines[i + 2].split()) == 0: start = i + 6 break for i in range(start, len(inlines)): if len(inlines[i].split()) == 0: break else: self.CHARGES.append(PT.to_Z(inlines[i].split()[0]))
def dummy_coordinate_names(vma): """ names of dummy atom coordinates """ syms = symbols(vma) name_mat = numpy.array(name_matrix(vma)) dummy_keys = [idx for idx, sym in enumerate(syms) if not pt.to_Z(sym)] dummy_names = [] for dummy_key in dummy_keys: for col_idx in range(3): dummy_name = next( filter(lambda x: x is not None, name_mat[dummy_key:, col_idx])) dummy_names.append(dummy_name) dummy_names = tuple(dummy_names) return dummy_names
def _format_geom_str(geo): """ Write the geometry section of the input file geometry in Angstroms """ # Format the strings for the xyz coordinates geom_str = '' for i, (sym, coords) in enumerate(geo): anum = int(ptab.to_Z(sym)) coords = [coord * BOHR2ANG for coord in coords] coords_str = '{0:>14.8f}{1:>14.8f}{2:>14.8f}'.format( coords[0], coords[1], coords[2]) geom_str += '{0:2d}{1:4d}{2:4d}{3}\n'.format(i + 1, anum, 0, coords_str) return geom_str
def _format_grad_str(geom, grad): """ Write the gradient section of the input file grads in Hartrees/Bohr """ atom_list = [] for i, (sym, _) in enumerate(geom): atom_list.append(int(ptab.to_Z(sym))) # Format the strings for the xyz gradients full_grads_str = '' for i, grads in enumerate(grad): grads_str = '{0:>14.8f}{1:>14.8f}{2:>14.8f}'.format( grads[0], grads[1], grads[2]) full_grads_str += '{0:2d}{1:4d}{2}\n'.format(i + 1, atom_list[i], grads_str) return full_grads_str
def _format_geom_str(geom): """ Formats the geometry into a string used for the ProjRot input file. :param geoms: geometries (Angstrom) :type geoms: list :rtype: str """ # Format the strings for the xyz coordinates geom_str = '' for i, (sym, coords) in enumerate(geom): anum = int(ptab.to_Z(sym)) coords = [coord * BOHR2ANG for coord in coords] coords_str = '{0:>14.8f}{1:>14.8f}{2:>14.8f}'.format( coords[0], coords[1], coords[2]) geom_str += '{0:2d}{1:4d}{2:4d}{3}\n'.format(i + 1, anum, 0, coords_str) return remove_trail_whitespace(geom_str)
def info_getter(lines): get_geom = False for line in lines: if get_geom == True: geometry_atoms = line.split() self.CHARGES.append(float(PT.to_Z(geometry_atoms[0]))) self.CARTESIANS += [ float(coordinate) / AU_TO_ANG for coordinate in geometry_atoms[1:4] ] self.NATOMS += 1 elif "geometry" in line: get_geom = True continue elif "functional" in line: functional_line = line.split(":") self.FUNCTIONAL = functional_line[1].strip().replace( "\n", "") else: continue
def _format_grad_str(geom, grad): """ Formats the gradient into a string used for the ProjRot input file. :param geom: geometries (Angstrom) :type geom: list :param grads: gradients (Eh/Bohr) :type grads: list :rtype: str """ atom_list = [] for i, (sym, _) in enumerate(geom): atom_list.append(int(ptab.to_Z(sym))) # Format the strings for the xyz gradients full_grads_str = '' for i, grads in enumerate(grad): grads_str = '{0:>14.8f}{1:>14.8f}{2:>14.8f}'.format( grads[0], grads[1], grads[2]) full_grads_str += '{0:2d}{1:4d}{2}\n'.format(i + 1, atom_list[i], grads_str) return remove_trail_whitespace(full_grads_str)
def without_dummy_atoms(xgr): """ remove dummy atoms from the graph """ atm_sym_dct = atom_symbols(xgr) atm_keys = [key for key, sym in atm_sym_dct.items() if pt.to_Z(sym)] return subgraph(xgr, atm_keys)
def _specifiers(idx): key_mat_row = key_mat[idx] idxs = tuple(filter(lambda x: x is not None and syms, key_mat_row)) if without_dummies: idxs = tuple(idx for idx in idxs if pt.to_Z(syms[idx])) return idxs
def _dependents(idx): idxs = [idx_ for idx_, row in enumerate(key_mat) if idx in row] if without_dummies: idxs = tuple(idx for idx in idxs if pt.to_Z(syms[idx])) return tuple(idxs)
def dummy_atom_indices(geo): """ indices of dummy atoms in this geometry (Replace w/ above at some pt) """ syms = symbols(geo) dummy_idxs = [idx for idx, sym in enumerate(syms) if not pt.to_Z(sym)] return tuple(dummy_idxs)