def mol_to_geom(mol): # almost idential to PySCF: # `geomopt.berny_solver.to_berny_geom(mol)` species = [mol.atom_symbol(i) for i in range(mol.natm)] coords = mol.atom_coords() * lib.param.BOHR geom = geomlib.Geometry(species, coords) return geom
def get_qm_geom(lig_geom, qm2mm_idx, qmatm_idx, prt_geom): ''' Get the QM geom from ligand and protein geometry (QM regions are on both ligand and protein) lig_geom (geomlib.Geometry): ligand (sym, xyz) qm2mm_idx (dict): atmID = mm_idx qmatm_idx (dict): atmID = qm_idx prt_geom (geomlib.Geometry): protein (sym, xyz) ''' #import copy qm_species = [] # copy.copy(lig_geom.species) qm_crds = [] # copy.copy(list(lig_geom.coords)) pos_ca = {} pos_cb = {} for atmId in qm2mm_idx: resId, atomName = atmId.split(':') mm_idx = qm2mm_idx[atmId] qm_idx = qmatm_idx[atmId] if resId in ['LIG1']: x, y, z = lig_geom.coords[mm_idx] sym = lig_geom.species[mm_idx] else: x, y, z = prt_geom.coords[mm_idx] sym = prt_geom.species[mm_idx] if atomName == 'CA': pos_ca[resId] = np.array([x, y, z]) if atomName == 'CB': pos_cb[resId] = np.array([x, y, z]) qm_species.append(sym) qm_crds.append([x, y, z]) for resId in pos_ca: pab = pos_ca[resId] - pos_cb[resId] rab = np.sqrt(np.einsum('i,i', pab, pab)) x, y, z = pos_cb[resId] + pab / rab atmId = resId + ':' + 'CA' idx = qmatm_idx[atmId] qm_species[idx] = 'H' #print(idx, 'before', qm_crds[idx], 'after', x, y, z) qm_crds[idx] = [x, y, z] #print('qm_species', qm_species) #print('qm_crds', qm_crds) # sys.exit() return geomlib.Geometry(qm_species, qm_crds)
def _load_geom(fname, qmResNames={}, l_protein=False): ext = fname.split('.')[-1] if ext != 'pdb': print("The pdb file is supported for the geometry") sys.exit() l_pdb = open(fname, 'r').readlines() species = [] coords = [] qm2mm_idx = {} # index from QM atoms to MM atoms # for resName in qmResNames: # qm_atoms[resName] = [] index = 0 for line in l_pdb: if line[:6] in ['ATOM ', 'HETATM']: atomName = line[12:16].strip() resName = line[17:20].strip() resNumber = line[22:26].strip() sym = line[76:78].strip() words = line[30:].split() coords.append([float(x) for x in words[0:3]]) species.append(sym) resId = resName + resNumber atmId = resId + ':' + atomName if resId in qmResNames: if l_protein: if atomName not in ['O', 'H', 'OXT', 'H1', 'H2', 'H3']: """ Peptide bonds, N-terminus, and C-terminus are not added into a QM residue CB--CA will be replaced with CB--H (H is a linked atom) We add 'C', 'N', and 'HA' into the QM region since they are covalently bonded to 'CA'. We will not estimate the Coulomb interaction and vdW interaction between them ('C', 'N', 'HA') and the QM particles. """ qm2mm_idx[atmId] = index else: qm2mm_idx[atmId] = index index += 1 return geomlib.Geometry(species, coords), qm2mm_idx
def to_berny_geom(mol, include_ghost=INCLUDE_GHOST): atom_charges = mol.atom_charges() if include_ghost: # Symbol Ghost is not supported in current version of pyberny #species = [mol.atom_symbol(i) if z != 0 else 'Ghost' # for i,z in enumerate(atom_charges)] species = [mol.atom_symbol(i) if z != 0 else 'H' for i,z in enumerate(atom_charges)] coords = mol.atom_coords() * lib.param.BOHR else: atmlst = numpy.where(atom_charges != 0)[0] # Exclude ghost atoms species = [mol.atom_symbol(i) for i in atmlst] coords = mol.atom_coords()[atmlst] * lib.param.BOHR # geomlib.Geometry is available in the new version of pyberny solver. (issue #212) if getattr(geomlib, 'Geometry', None): return geomlib.Geometry(species, coords) else: return geomlib.Molecule(species, coords)