def add_fake_water_atom(soup, res_type, bfactor): dummy_atom = pdbatoms.Atom() dummy_atom.pos = soup.atoms()[0].pos.copy() dummy_atom.type = "O" dummy_atom.bfactor = bfactor dummy_res = pdbatoms.Residue(res_type, '', 9999) dummy_res.insert_atom(dummy_atom) soup.append_residue(dummy_res)
def soup_from_psf(psf): """ Returns a Soup from a .psf file """ soup = pdbatoms.Soup() curr_res_num = None is_header = True for line in open(psf): if is_header: if "NATOM" in line: n_atom = int(line.split()[0]) is_header = False continue words = line.split() atom_num = int(words[0]) chain_id = words[1] res_num = int(words[2]) res_type = words[3] atom_type = words[4] charge = float(words[6]) mass = float(words[7]) if chain_id.startswith('WT') or chain_id.startswith('ION'): is_hetatm = True chain_id = " " else: is_hetatm = False chain_id = chain_id[0] if curr_res_num != res_num: res = pdbatoms.Residue(res_type, chain_id, res_num) soup.append_residue(res) curr_res_num = res_num atom = pdbatoms.Atom() atom.vel = v3.vector() atom.chain_id = chain_id atom.is_hetatm = is_hetatm atom.num = atom_num atom.res_num = res_num atom.res_type = res_type atom.type = atom_type atom.mass = mass atom.charge = charge atom.element = data.guess_element(res_type, atom_type) soup.insert_atom(-1, atom) if len(soup.atoms()) == n_atom: break convert_to_pdb_atom_names(soup) return soup
def write_pdb(self, pdb, res_type="HOH", atom_type="O", element="O"): i_res = 1 with open(pdb, 'w') as f: for i in range(self.n): for j in range(self.n): for k in range(self.n): l = i * self.n_sq + j * self.n + k if self.array[l]: atom = pdbatoms.Atom() atom.pos = self.pos(i, j, k) atom.type = atom_type atom.is_hetatm = True atom.element = element atom.res_type = res_type atom.res_num = i_res atom.num = i_res f.write(atom.pdb_str() + '\n')
def AtomFromGroLine(line): """ Returns an Atom object from a .gro atom line. """ atom = pdbatoms.Atom() atom.res_num = int(line[0:5]) atom.res_type = line[5:8].strip() atom.type = line[10:15].strip(" ") atom.element = data.guess_element(atom.res_type, line[12:15]) atom.num = int(line[15:20]) # 10 x multiplier converts from nm to angstroms x = 10.0 * float(line[20:28]) y = 10.0 * float(line[28:36]) z = 10.0 * float(line[36:44]) v3.set_vector(atom.pos, x, y, z) if len(line) > 62: # 10 x multiplier converts from nm to angstroms x = 10.0 * float(line[44:52]) y = 10.0 * float(line[52:60]) z = 10.0 * float(line[60:68]) v3.set_vector(atom.vel, x, y, z) return atom
def soup_from_topology(topology): """ Returns a Soup from a topology dictionary. """ soup = pdbatoms.Soup() chain_id = '' n_res = topology['NRES'] n_atom = topology['NATOM'] for i_res in range(n_res): res_type = topology['RESIDUE_LABEL'][i_res].strip() if res_type == "WAT": res_type = "HOH" res = pdbatoms.Residue(res_type, chain_id, i_res + 1) soup.append_residue(res) res = soup.residue(i_res) i_atom_start = topology['RESIDUE_POINTER'][i_res] - 1 if i_res == n_res - 1: i_atom_end = n_atom else: i_atom_end = topology['RESIDUE_POINTER'][i_res + 1] - 1 for i_atom in range(i_atom_start, i_atom_end): atom = pdbatoms.Atom() atom.vel = v3.vector() atom.num = i_atom + 1 atom.res_num = i_res + 1 atom.res_type = res_type atom.type = topology['ATOM_NAME'][i_atom].strip() atom.mass = topology['MASS'][i_atom] atom.charge = topology['CHARGE'][i_atom] / sqrt_of_k atom.element = data.guess_element(atom.res_type, atom.type) soup.insert_atom(-1, atom) convert_to_pdb_atom_names(soup) if topology['IFBOX'] > 0: # create dummy dimension to ensure box dimension recognized soup.box_dimension_str = "1.000000 1.0000000 1.000000" return soup