def soup_from_top_and_crd_or_rst(top, crd_or_rst): """ Returns a Soup from AMBER .top and .crd/.rst files. """ topology = read_top(top) soup = soup_from_topology(topology) load_crd_or_rst_into_soup(soup, crd_or_rst) protein.find_chains(soup) if topology['IFBOX'] > 0: # if periodic cells are in .crd or .rst then save # for later, if we need to write modified .crd or .rst lines = open(crd_or_rst, "r").readlines() lines = [l for l in reversed(lines) if l.strip()] soup.box_dimension_str = lines[0].rstrip() return soup
def soup_from_top_gro(top, gro, skip_solvent=False): """ Returns a Soup built from GROMACS restart files. If skip_solvent=True, will skip all solvent molecules. """ util.check_output(top) util.check_output(gro) soup = pdbatoms.Soup() soup.remaining_text = "" soup.n_remaining_text = 0 atoms = [] # Read from .gro because .top does not contain water # residue information, which is "inferred" lines = open(gro, 'r').readlines() for i_line, line in enumerate(lines[2:-1]): atom = AtomFromGroLine(line) if skip_solvent and atom.res_type == "SOL": soup.remaining_text = "".join(lines[i_line+2:-1]) soup.n_remaining_text = len(lines[i_line+2:-1]) break atoms.append(atom) soup.box = [float(w) for w in lines[-1].split()] for atom, (mass, q, chain_id) in zip(atoms, read_top(top)): atom.mass = mass atom.charge = q curr_res_num = -1 for a in atoms: if curr_res_num != a.res_num: res = pdbatoms.Residue( a.res_type, a.chain_id, a.res_num) soup.append_residue(res.copy()) curr_res_num = a.res_num soup.insert_atom(-1, a) convert_to_pdb_atom_names(soup) protein.find_chains(soup) return soup
def soup_from_top_gro(top, gro, skip_solvent=False): """ Returns a Soup built from GROMACS restart files. If skip_solvent=True, will skip all solvent molecules. """ util.check_output(top) util.check_output(gro) soup = pdbatoms.Soup() soup.remaining_text = "" soup.n_remaining_text = 0 atoms = [] # Read from .gro because .top does not contain water # residue information, which is "inferred" lines = open(gro, 'r').readlines() for i_line, line in enumerate(lines[2:-1]): atom = AtomFromGroLine(line) if skip_solvent and atom.res_type == "SOL": soup.remaining_text = "".join(lines[i_line + 2:-1]) soup.n_remaining_text = len(lines[i_line + 2:-1]) break atoms.append(atom) soup.box = [float(w) for w in lines[-1].split()] for atom, (mass, q, chain_id) in zip(atoms, read_top(top)): atom.mass = mass atom.charge = q curr_res_num = -1 for a in atoms: if curr_res_num != a.res_num: res = pdbatoms.Residue(a.res_type, a.chain_id, a.res_num) soup.append_residue(res.copy()) curr_res_num = a.res_num soup.insert_atom(-1, a) convert_to_pdb_atom_names(soup) protein.find_chains(soup) return soup