Re: [PyMOL] loading gro files From: Tsjerk Wassenaar - 2011-08-18 07:39:54 Attachments: gro2pdb.py ```Hey :) Here is an all Python solution to load a .gro file, including the box vectors. It simply converts to PDB format and calls cmd.read_pdbstr... It supports multimodel files. I'll probably add a mechanism to identify chains from breaks, as the .gro format does not use chain identifiers, and may add gzip support. Later I'll also add MARTINI coarse graining, while I'm at it :) Hope it helps, Tsjerk ### from pymol import cmd import math _pdbline = "ATOM %5i %-3s %3s%2s%4i %8.3f%8.3f%8.3f%6.2f%6.2f %1s \n" _pdbBoxLine = "CRYST1%9.3f%9.3f%9.3f%7.2f%7.2f%7.2f P 1 1\n" d2r = math.pi/180 def cos_angle(a,b): p = sum([i*j for i,j in zip(a,b)]) q = math.sqrt(sum([i*i for i in a])*sum([j*j for j in b])) return min(max(-1,p/q),1) def norm2(a): return sum([i*i for i in a]) def norm(a): return math.sqrt(norm2(a)) def groBoxRead(a): b = [10*float(i) for i in a.split()] + 6*[0] # Padding for rectangular boxes return b[0],b[3],b[4],b[5],b[1],b[6],b[7],b[8],b[2] def groAtom(a): #012345678901234567890123456789012345678901234567890 # 1PRN N 1 4.168 11.132 5.291 ## ===> atom name, res name, res id, chain x, y, z return (a[10:15].strip(),a[5:10].strip(),int(a[:5])," ",10*float(a[20:28]),10*float(a[28:36]),10*float(a[36:44])) # Simple GRO iterator def groFrameIterator(stream): while True: title = stream.readline() natoms = stream.readline().strip() if not natoms: break natoms = int(natoms) atoms = [groAtom(stream.readline()) for i in range(natoms)] box = groBoxRead(stream.readline()) yield title, atoms, box def pdbOut(atom,i=1): return _pdbline%((i,) + (atom[0][:3],) + (atom[1],) + (atom[3],) + (atom[2],) + atom[4:] + (1,40) + (atom[0][0],)) def pdbBoxString(box): nu = math.sqrt(norm2(box[0:3])) nv = math.sqrt(norm2(box[3:6])) nw = math.sqrt(norm2(box[6:9])) alpha = nv*nw == 0 and 90 or math.acos(cos_angle(box[3:6],box[6:9]))/d2r beta = nu*nw == 0 and 90 or math.acos(cos_angle(box[0:3],box[6:9]))/d2r gamma = nu*nv == 0 and 90 or math.acos(cos_angle(box[0:3],box[6:9]))/d2r return _pdbBoxLine % (norm(box[0:3]),norm(box[3:6]),norm(box[6:9]),alpha,beta,gamma) def gro(filename): objname = filename[1+filename.rfind("/"):filename.rfind(".")] pdb = [] model = 1 for title, atoms, box in groFrameIterator(open(filename)): pdb.append("MODEL %8d"%model) pdb.append(pdbBoxString(box)) pdb.extend([pdbOut(atom,i) for atom, i in zip(atoms,range(1,len(atoms)+1))]) pdb.append("ENDMDL") model += 1 cmd.read_pdbstr("\n".join(pdb),objname) cmd.extend("gro",gro) ### On Wed, Aug 17, 2011 at 5:11 AM, Jason Vertrees wrote: > Hi Michael, > > PyMOL knows about gromacs files, but needs to better handle .gro > files, specifically. Currently you have to export to a PDB to read the > topology. > > Please file this on the open-source tracker > (https://sourceforge.net/tracker/?group_id=4546) and I'll get to it > ASAP. > > Cheers, > > -- Jason > > On Mon, Aug 15, 2011 at 8:19 PM, Michael Daily wrote: >> Hi all, >> >> Is there a direct way to load a gromacs structure file (.gro) in PyMOL? I >> know it's simple to convert them to pdb using editconf, but I want to load >> gro files directly (as you can in vmd) because they permit higher max. atom >> and residue numbers (100K vs. 10K for pdb) and permit longer residue names >> (4 chars vs. 3 for vmd). >> >> Thanks, >> Mike >> >> -- >> ==================================== >> Michael D. Daily >> Postdoctoral research associate >> Pacific Northwest National Lab (PNNL) >> 509-375-4581 >> (formerly Qiang Cui group, University of Wisconsin-Madison) >> >> ------------------------------------------------------------------------------ >> uberSVN's rich system and user administration capabilities and model >> configuration take the hassle out of deploying and managing Subversion and >> the tools developers use with it. Learn more about uberSVN and get a free >> download at:  http://p.sf.net/sfu/wandisco-dev2dev >> >> _______________________________________________ >> PyMOL-users mailing list (PyMOL-users@...) >> Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users >> Archives: http://www.mail-archive.com/pymol-users@... >> > > > > -- > Jason Vertrees, PhD > PyMOL Product Manager > Schrodinger, LLC > > (e) Jason.Vertrees@... > (o) +1 (603) 374-7120 > > ------------------------------------------------------------------------------ > Get a FREE DOWNLOAD! and learn more about uberSVN rich system, > user administration capabilities and model configuration. Take > the hassle out of deploying and managing Subversion and the > tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2 > _______________________________________________ > PyMOL-users mailing list (PyMOL-users@...) > Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users > Archives: http://www.mail-archive.com/pymol-users@... > -- Tsjerk A. Wassenaar, Ph.D. post-doctoral researcher Molecular Dynamics Group * Groningen Institute for Biomolecular Research and Biotechnology * Zernike Institute for Advanced Materials University of Groningen The Netherlands ```

 [PyMOL] loading gro files From: Michael Daily - 2011-08-16 00:19:49 Attachments: Message as HTML ```Hi all, Is there a direct way to load a gromacs structure file (.gro) in PyMOL? I know it's simple to convert them to pdb using editconf, but I want to load gro files directly (as you can in vmd) because they permit higher max. atom and residue numbers (100K vs. 10K for pdb) and permit longer residue names (4 chars vs. 3 for vmd). Thanks, Mike -- ==================================== Michael D. Daily Postdoctoral research associate Pacific Northwest National Lab (PNNL) 509-375-4581 (formerly Qiang Cui group, University of Wisconsin-Madison) ```
 Re: [PyMOL] loading gro files From: Marius Retegan - 2011-08-16 16:01:40 ```Maybe this can help you http://sourceforge.net/mailarchive/message.php?msg_id=19472192 Cheers, Marius On Tue, Aug 16, 2011 at 2:19 AM, Michael Daily wrote: > Hi all, > > Is there a direct way to load a gromacs structure file (.gro) in PyMOL? I > know it's simple to convert them to pdb using editconf, but I want to load > gro files directly (as you can in vmd) because they permit higher max. atom > and residue numbers (100K vs. 10K for pdb) and permit longer residue names > (4 chars vs. 3 for vmd). > > Thanks, > Mike > > -- > ==================================== > Michael D. Daily > Postdoctoral research associate > Pacific Northwest National Lab (PNNL) > 509-375-4581 > (formerly Qiang Cui group, University of Wisconsin-Madison) > > ------------------------------------------------------------------------------ > uberSVN's rich system and user administration capabilities and model > configuration take the hassle out of deploying and managing Subversion and > the tools developers use with it. Learn more about uberSVN and get a free > download at:  http://p.sf.net/sfu/wandisco-dev2dev > > _______________________________________________ > PyMOL-users mailing list (PyMOL-users@...) > Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users > Archives: http://www.mail-archive.com/pymol-users@... > ```
 Re: [PyMOL] loading gro files From: Jason Vertrees - 2011-08-17 03:18:32 ```Hi Michael, PyMOL knows about gromacs files, but needs to better handle .gro files, specifically. Currently you have to export to a PDB to read the topology. Please file this on the open-source tracker (https://sourceforge.net/tracker/?group_id=4546) and I'll get to it ASAP. Cheers, -- Jason On Mon, Aug 15, 2011 at 8:19 PM, Michael Daily wrote: > Hi all, > > Is there a direct way to load a gromacs structure file (.gro) in PyMOL? I > know it's simple to convert them to pdb using editconf, but I want to load > gro files directly (as you can in vmd) because they permit higher max. atom > and residue numbers (100K vs. 10K for pdb) and permit longer residue names > (4 chars vs. 3 for vmd). > > Thanks, > Mike > > -- > ==================================== > Michael D. Daily > Postdoctoral research associate > Pacific Northwest National Lab (PNNL) > 509-375-4581 > (formerly Qiang Cui group, University of Wisconsin-Madison) > > ------------------------------------------------------------------------------ > uberSVN's rich system and user administration capabilities and model > configuration take the hassle out of deploying and managing Subversion and > the tools developers use with it. Learn more about uberSVN and get a free > download at:  http://p.sf.net/sfu/wandisco-dev2dev > > _______________________________________________ > PyMOL-users mailing list (PyMOL-users@...) > Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users > Archives: http://www.mail-archive.com/pymol-users@... > -- Jason Vertrees, PhD PyMOL Product Manager Schrodinger, LLC (e) Jason.Vertrees@... (o) +1 (603) 374-7120 ```
 Re: [PyMOL] loading gro files From: Tsjerk Wassenaar - 2011-08-18 07:39:54 Attachments: gro2pdb.py ```Hey :) Here is an all Python solution to load a .gro file, including the box vectors. It simply converts to PDB format and calls cmd.read_pdbstr... It supports multimodel files. I'll probably add a mechanism to identify chains from breaks, as the .gro format does not use chain identifiers, and may add gzip support. Later I'll also add MARTINI coarse graining, while I'm at it :) Hope it helps, Tsjerk ### from pymol import cmd import math _pdbline = "ATOM %5i %-3s %3s%2s%4i %8.3f%8.3f%8.3f%6.2f%6.2f %1s \n" _pdbBoxLine = "CRYST1%9.3f%9.3f%9.3f%7.2f%7.2f%7.2f P 1 1\n" d2r = math.pi/180 def cos_angle(a,b): p = sum([i*j for i,j in zip(a,b)]) q = math.sqrt(sum([i*i for i in a])*sum([j*j for j in b])) return min(max(-1,p/q),1) def norm2(a): return sum([i*i for i in a]) def norm(a): return math.sqrt(norm2(a)) def groBoxRead(a): b = [10*float(i) for i in a.split()] + 6*[0] # Padding for rectangular boxes return b[0],b[3],b[4],b[5],b[1],b[6],b[7],b[8],b[2] def groAtom(a): #012345678901234567890123456789012345678901234567890 # 1PRN N 1 4.168 11.132 5.291 ## ===> atom name, res name, res id, chain x, y, z return (a[10:15].strip(),a[5:10].strip(),int(a[:5])," ",10*float(a[20:28]),10*float(a[28:36]),10*float(a[36:44])) # Simple GRO iterator def groFrameIterator(stream): while True: title = stream.readline() natoms = stream.readline().strip() if not natoms: break natoms = int(natoms) atoms = [groAtom(stream.readline()) for i in range(natoms)] box = groBoxRead(stream.readline()) yield title, atoms, box def pdbOut(atom,i=1): return _pdbline%((i,) + (atom[0][:3],) + (atom[1],) + (atom[3],) + (atom[2],) + atom[4:] + (1,40) + (atom[0][0],)) def pdbBoxString(box): nu = math.sqrt(norm2(box[0:3])) nv = math.sqrt(norm2(box[3:6])) nw = math.sqrt(norm2(box[6:9])) alpha = nv*nw == 0 and 90 or math.acos(cos_angle(box[3:6],box[6:9]))/d2r beta = nu*nw == 0 and 90 or math.acos(cos_angle(box[0:3],box[6:9]))/d2r gamma = nu*nv == 0 and 90 or math.acos(cos_angle(box[0:3],box[6:9]))/d2r return _pdbBoxLine % (norm(box[0:3]),norm(box[3:6]),norm(box[6:9]),alpha,beta,gamma) def gro(filename): objname = filename[1+filename.rfind("/"):filename.rfind(".")] pdb = [] model = 1 for title, atoms, box in groFrameIterator(open(filename)): pdb.append("MODEL %8d"%model) pdb.append(pdbBoxString(box)) pdb.extend([pdbOut(atom,i) for atom, i in zip(atoms,range(1,len(atoms)+1))]) pdb.append("ENDMDL") model += 1 cmd.read_pdbstr("\n".join(pdb),objname) cmd.extend("gro",gro) ### On Wed, Aug 17, 2011 at 5:11 AM, Jason Vertrees wrote: > Hi Michael, > > PyMOL knows about gromacs files, but needs to better handle .gro > files, specifically. Currently you have to export to a PDB to read the > topology. > > Please file this on the open-source tracker > (https://sourceforge.net/tracker/?group_id=4546) and I'll get to it > ASAP. > > Cheers, > > -- Jason > > On Mon, Aug 15, 2011 at 8:19 PM, Michael Daily wrote: >> Hi all, >> >> Is there a direct way to load a gromacs structure file (.gro) in PyMOL? I >> know it's simple to convert them to pdb using editconf, but I want to load >> gro files directly (as you can in vmd) because they permit higher max. atom >> and residue numbers (100K vs. 10K for pdb) and permit longer residue names >> (4 chars vs. 3 for vmd). >> >> Thanks, >> Mike >> >> -- >> ==================================== >> Michael D. Daily >> Postdoctoral research associate >> Pacific Northwest National Lab (PNNL) >> 509-375-4581 >> (formerly Qiang Cui group, University of Wisconsin-Madison) >> >> ------------------------------------------------------------------------------ >> uberSVN's rich system and user administration capabilities and model >> configuration take the hassle out of deploying and managing Subversion and >> the tools developers use with it. Learn more about uberSVN and get a free >> download at:  http://p.sf.net/sfu/wandisco-dev2dev >> >> _______________________________________________ >> PyMOL-users mailing list (PyMOL-users@...) >> Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users >> Archives: http://www.mail-archive.com/pymol-users@... >> > > > > -- > Jason Vertrees, PhD > PyMOL Product Manager > Schrodinger, LLC > > (e) Jason.Vertrees@... > (o) +1 (603) 374-7120 > > ------------------------------------------------------------------------------ > Get a FREE DOWNLOAD! and learn more about uberSVN rich system, > user administration capabilities and model configuration. Take > the hassle out of deploying and managing Subversion and the > tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2 > _______________________________________________ > PyMOL-users mailing list (PyMOL-users@...) > Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users > Archives: http://www.mail-archive.com/pymol-users@... > -- Tsjerk A. Wassenaar, Ph.D. post-doctoral researcher Molecular Dynamics Group * Groningen Institute for Biomolecular Research and Biotechnology * Zernike Institute for Advanced Materials University of Groningen The Netherlands ```
 Re: [PyMOL] loading gro files From: Joseph André - 2011-08-18 07:54:13 Attachments: Message as HTML ```Hi Tsjerk, Thanks for the script. It works great on my protein. However when I try to load the solvated system > 100.000 atoms I have problems with water molecules. Is it possible to handle gro files with more than 100.000 atoms and 9999 residues? Best On Thu, Aug 18, 2011 at 9:39 AM, Tsjerk Wassenaar wrote: > Hey :) > > Here is an all Python solution to load a .gro file, including the box > vectors. It simply converts to PDB format and calls cmd.read_pdbstr... > It supports multimodel files. I'll probably add a mechanism to > identify chains from breaks, as the .gro format does not use chain > identifiers, and may add gzip support. Later I'll also add MARTINI > coarse graining, while I'm at it :) > > Hope it helps, > > Tsjerk > > > ### > > from pymol import cmd > import math > > _pdbline = "ATOM %5i %-3s %3s%2s%4i %8.3f%8.3f%8.3f%6.2f%6.2f > %1s \n" > _pdbBoxLine = "CRYST1%9.3f%9.3f%9.3f%7.2f%7.2f%7.2f P 1 1\n" > > d2r = math.pi/180 > > def cos_angle(a,b): > p = sum([i*j for i,j in zip(a,b)]) > q = math.sqrt(sum([i*i for i in a])*sum([j*j for j in b])) > return min(max(-1,p/q),1) > > def norm2(a): > return sum([i*i for i in a]) > > def norm(a): > return math.sqrt(norm2(a)) > > def groBoxRead(a): > b = [10*float(i) for i in a.split()] + 6*[0] # Padding for rectangular > boxes > return b[0],b[3],b[4],b[5],b[1],b[6],b[7],b[8],b[2] > > def groAtom(a): > #012345678901234567890123456789012345678901234567890 > # 1PRN N 1 4.168 11.132 5.291 > ## ===> atom name, res name, res id, chain > x, y, z > return (a[10:15].strip(),a[5:10].strip(),int(a[:5])," > ",10*float(a[20:28]),10*float(a[28:36]),10*float(a[36:44])) > > # Simple GRO iterator > def groFrameIterator(stream): > while True: > title = stream.readline() > natoms = stream.readline().strip() > if not natoms: > break > natoms = int(natoms) > atoms = [groAtom(stream.readline()) for i in range(natoms)] > box = groBoxRead(stream.readline()) > yield title, atoms, box > > def pdbOut(atom,i=1): > return _pdbline%((i,) + (atom[0][:3],) + (atom[1],) + (atom[3],) + > (atom[2],) + atom[4:] + (1,40) + (atom[0][0],)) > > def pdbBoxString(box): > nu = math.sqrt(norm2(box[0:3])) > nv = math.sqrt(norm2(box[3:6])) > nw = math.sqrt(norm2(box[6:9])) > > alpha = nv*nw == 0 and 90 or math.acos(cos_angle(box[3:6],box[6:9]))/d2r > beta = nu*nw == 0 and 90 or math.acos(cos_angle(box[0:3],box[6:9]))/d2r > gamma = nu*nv == 0 and 90 or math.acos(cos_angle(box[0:3],box[6:9]))/d2r > > return _pdbBoxLine % > (norm(box[0:3]),norm(box[3:6]),norm(box[6:9]),alpha,beta,gamma) > > def gro(filename): > objname = filename[1+filename.rfind("/"):filename.rfind(".")] > pdb = [] > model = 1 > for title, atoms, box in groFrameIterator(open(filename)): > pdb.append("MODEL %8d"%model) > pdb.append(pdbBoxString(box)) > pdb.extend([pdbOut(atom,i) for atom, i in > zip(atoms,range(1,len(atoms)+1))]) > pdb.append("ENDMDL") > model += 1 > cmd.read_pdbstr("\n".join(pdb),objname) > > cmd.extend("gro",gro) > > ### > > On Wed, Aug 17, 2011 at 5:11 AM, Jason Vertrees > wrote: > > Hi Michael, > > > > PyMOL knows about gromacs files, but needs to better handle .gro > > files, specifically. Currently you have to export to a PDB to read the > > topology. > > > > Please file this on the open-source tracker > > (https://sourceforge.net/tracker/?group_id=4546) and I'll get to it > > ASAP. > > > > Cheers, > > > > -- Jason > > > > On Mon, Aug 15, 2011 at 8:19 PM, Michael Daily > wrote: > >> Hi all, > >> > >> Is there a direct way to load a gromacs structure file (.gro) in PyMOL? > I > >> know it's simple to convert them to pdb using editconf, but I want to > load > >> gro files directly (as you can in vmd) because they permit higher max. > atom > >> and residue numbers (100K vs. 10K for pdb) and permit longer residue > names > >> (4 chars vs. 3 for vmd). > >> > >> Thanks, > >> Mike > >> > >> -- > >> ==================================== > >> Michael D. Daily > >> Postdoctoral research associate > >> Pacific Northwest National Lab (PNNL) > >> 509-375-4581 > >> (formerly Qiang Cui group, University of Wisconsin-Madison) > >> > >> > ------------------------------------------------------------------------------ > >> uberSVN's rich system and user administration capabilities and model > >> configuration take the hassle out of deploying and managing Subversion > and > >> the tools developers use with it. Learn more about uberSVN and get a > free > >> download at: http://p.sf.net/sfu/wandisco-dev2dev > >> > >> _______________________________________________ > >> PyMOL-users mailing list (PyMOL-users@...) > >> Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users > >> Archives: http://www.mail-archive.com/pymol-users@... > >> > > > > > > > > -- > > Jason Vertrees, PhD > > PyMOL Product Manager > > Schrodinger, LLC > > > > (e) Jason.Vertrees@... > > (o) +1 (603) 374-7120 > > > > > ------------------------------------------------------------------------------ > > Get a FREE DOWNLOAD! and learn more about uberSVN rich system, > > user administration capabilities and model configuration. Take > > the hassle out of deploying and managing Subversion and the > > tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2 > > _______________________________________________ > > PyMOL-users mailing list (PyMOL-users@...) > > Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users > > Archives: http://www.mail-archive.com/pymol-users@... > > > > > > -- > Tsjerk A. Wassenaar, Ph.D. > > post-doctoral researcher > Molecular Dynamics Group > * Groningen Institute for Biomolecular Research and Biotechnology > * Zernike Institute for Advanced Materials > University of Groningen > The Netherlands > > > ------------------------------------------------------------------------------ > Get a FREE DOWNLOAD! and learn more about uberSVN rich system, > user administration capabilities and model configuration. Take > the hassle out of deploying and managing Subversion and the > tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2 > _______________________________________________ > PyMOL-users mailing list (PyMOL-users@...) > Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users > Archives: http://www.mail-archive.com/pymol-users@... > -- Joseph ANDRE ```
 Re: [PyMOL] loading gro files From: Tsjerk Wassenaar - 2011-08-18 08:40:53 ```Hi Joseph, Sorry about that. A bit naive with the numbering. To fix it, change the function def pdbOut(atom,i=1): return _pdbline%((i,) + (atom[0][:3],) + (atom[1],) + (atom[3],) + (atom[2],) + atom[4:] + (1,40) + (atom[0][0],)) to def pdbOut(atom,i=1): stuff = [i%1e5,atom[0][:3],atom[1],atom[3],atom[2]%1e4]+list(atom[4:])+[1,40,atom[0][0]] return _pdbline % tuple(stuff) It worked for me on a .gro file with 160k atoms :) Cheers, Tsjerk 2011/8/18 Joseph André : > Hi Tsjerk, > Thanks for the script. It works great on my protein. However when I try to > load the solvated system > 100.000 atoms I have problems with water > molecules. Is it possible to handle gro files with more than 100.000 atoms > and 9999 residues? > Best > > On Thu, Aug 18, 2011 at 9:39 AM, Tsjerk Wassenaar wrote: >> >> Hey :) >> >> Here is an all Python solution to load a .gro file, including the box >> vectors. It simply converts to PDB format and calls cmd.read_pdbstr... >> It supports multimodel files. I'll probably add a mechanism to >> identify chains from breaks, as the .gro format does not use chain >> identifiers, and may add gzip support. Later I'll also add MARTINI >> coarse graining, while I'm at it :) >> >> Hope it helps, >> >> Tsjerk >> >> >> ### >> >> from pymol import cmd >> import math >> >> _pdbline    = "ATOM  %5i  %-3s %3s%2s%4i    %8.3f%8.3f%8.3f%6.2f%6.2f >>         %1s  \n" >> _pdbBoxLine = "CRYST1%9.3f%9.3f%9.3f%7.2f%7.2f%7.2f P 1           1\n" >> >> d2r = math.pi/180 >> >> def cos_angle(a,b): >>    p = sum([i*j for i,j in zip(a,b)]) >>    q = math.sqrt(sum([i*i for i in a])*sum([j*j for j in b])) >>    return min(max(-1,p/q),1) >> >> def norm2(a): >>    return sum([i*i for i in a]) >> >> def norm(a): >>    return math.sqrt(norm2(a)) >> >> def groBoxRead(a): >>    b = [10*float(i) for i in a.split()] + 6*[0] # Padding for rectangular >> boxes >>    return b[0],b[3],b[4],b[5],b[1],b[6],b[7],b[8],b[2] >> >> def groAtom(a): >>    #012345678901234567890123456789012345678901234567890 >>    #    1PRN      N    1   4.168  11.132   5.291 >>    ## ===> atom name,       res name,       res id,    chain >> x,                 y,                 z >>    return (a[10:15].strip(),a[5:10].strip(),int(a[:5])," >> ",10*float(a[20:28]),10*float(a[28:36]),10*float(a[36:44])) >> >> # Simple GRO iterator >> def groFrameIterator(stream): >>    while True: >>        title = stream.readline() >>        natoms = stream.readline().strip() >>        if not natoms: >>            break >>        natoms = int(natoms) >>        atoms  = [groAtom(stream.readline())  for i in range(natoms)] >>        box    = groBoxRead(stream.readline()) >>        yield title, atoms, box >> >> def pdbOut(atom,i=1): >>    return _pdbline%((i,) + (atom[0][:3],) + (atom[1],) + (atom[3],) + >> (atom[2],) + atom[4:] + (1,40) + (atom[0][0],)) >> >> def pdbBoxString(box): >>    nu = math.sqrt(norm2(box[0:3])) >>    nv = math.sqrt(norm2(box[3:6])) >>    nw = math.sqrt(norm2(box[6:9])) >> >>    alpha = nv*nw == 0 and 90 or >> math.acos(cos_angle(box[3:6],box[6:9]))/d2r >>    beta  = nu*nw == 0 and 90 or >> math.acos(cos_angle(box[0:3],box[6:9]))/d2r >>    gamma = nu*nv == 0 and 90 or >> math.acos(cos_angle(box[0:3],box[6:9]))/d2r >> >>    return _pdbBoxLine % >> (norm(box[0:3]),norm(box[3:6]),norm(box[6:9]),alpha,beta,gamma) >> >> def gro(filename): >>    objname = filename[1+filename.rfind("/"):filename.rfind(".")] >>    pdb     = [] >>    model   = 1 >>    for title, atoms, box in groFrameIterator(open(filename)): >>        pdb.append("MODEL %8d"%model) >>        pdb.append(pdbBoxString(box)) >>        pdb.extend([pdbOut(atom,i) for atom, i in >> zip(atoms,range(1,len(atoms)+1))]) >>        pdb.append("ENDMDL") >>        model += 1 >>    cmd.read_pdbstr("\n".join(pdb),objname) >> >> cmd.extend("gro",gro) >> >> ### >> >> On Wed, Aug 17, 2011 at 5:11 AM, Jason Vertrees >> wrote: >> > Hi Michael, >> > >> > PyMOL knows about gromacs files, but needs to better handle .gro >> > files, specifically. Currently you have to export to a PDB to read the >> > topology. >> > >> > Please file this on the open-source tracker >> > (https://sourceforge.net/tracker/?group_id=4546) and I'll get to it >> > ASAP. >> > >> > Cheers, >> > >> > -- Jason >> > >> > On Mon, Aug 15, 2011 at 8:19 PM, Michael Daily >> > wrote: >> >> Hi all, >> >> >> >> Is there a direct way to load a gromacs structure file (.gro) in PyMOL? >> >> I >> >> know it's simple to convert them to pdb using editconf, but I want to >> >> load >> >> gro files directly (as you can in vmd) because they permit higher max. >> >> atom >> >> and residue numbers (100K vs. 10K for pdb) and permit longer residue >> >> names >> >> (4 chars vs. 3 for vmd). >> >> >> >> Thanks, >> >> Mike >> >> >> >> -- >> >> ==================================== >> >> Michael D. Daily >> >> Postdoctoral research associate >> >> Pacific Northwest National Lab (PNNL) >> >> 509-375-4581 >> >> (formerly Qiang Cui group, University of Wisconsin-Madison) >> >> >> >> >> >> ------------------------------------------------------------------------------ >> >> uberSVN's rich system and user administration capabilities and model >> >> configuration take the hassle out of deploying and managing Subversion >> >> and >> >> the tools developers use with it. Learn more about uberSVN and get a >> >> free >> >> download at:  http://p.sf.net/sfu/wandisco-dev2dev >> >> >> >> _______________________________________________ >> >> PyMOL-users mailing list (PyMOL-users@...) >> >> Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users >> >> Archives: http://www.mail-archive.com/pymol-users@... >> >> >> > >> > >> > >> > -- >> > Jason Vertrees, PhD >> > PyMOL Product Manager >> > Schrodinger, LLC >> > >> > (e) Jason.Vertrees@... >> > (o) +1 (603) 374-7120 >> > >> > >> > ------------------------------------------------------------------------------ >> > Get a FREE DOWNLOAD! and learn more about uberSVN rich system, >> > user administration capabilities and model configuration. Take >> > the hassle out of deploying and managing Subversion and the >> > tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2 >> > _______________________________________________ >> > PyMOL-users mailing list (PyMOL-users@...) >> > Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users >> > Archives: http://www.mail-archive.com/pymol-users@... >> > >> >> >> >> -- >> Tsjerk A. Wassenaar, Ph.D. >> >> post-doctoral researcher >> Molecular Dynamics Group >> * Groningen Institute for Biomolecular Research and Biotechnology >> * Zernike Institute for Advanced Materials >> University of Groningen >> The Netherlands >> >> >> ------------------------------------------------------------------------------ >> Get a FREE DOWNLOAD! and learn more about uberSVN rich system, >> user administration capabilities and model configuration. Take >> the hassle out of deploying and managing Subversion and the >> tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2 >> _______________________________________________ >> PyMOL-users mailing list (PyMOL-users@...) >> Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users >> Archives: http://www.mail-archive.com/pymol-users@... > > > > -- > Joseph ANDRE > > > -- Tsjerk A. Wassenaar, Ph.D. post-doctoral researcher Molecular Dynamics Group * Groningen Institute for Biomolecular Research and Biotechnology * Zernike Institute for Advanced Materials University of Groningen The Netherlands ```
 Re: [PyMOL] loading gro files From: Thomas Holder - 2011-08-18 09:43:56 ```To keep the original residue numbers from the gro file, you could also temporarily store additional numbering in the segment identifier, and after loading get it back from there: _pdbline = "ATOM %5i %-3s %3s%2s%4i" +\ " %8.3f%8.3f%8.3f%6.2f%6.2f %4s%2s \n" def pdbOut(atom,i=1): segi = '%02d%02d' % (i/100000,atom[2]/10000) stuff = [i%1e5,atom[0][:3],atom[1],atom[3],atom[2]%1e4] +\ list(atom[4:])+[1,40,segi,atom[0][0]] return _pdbline % tuple(stuff) And after cmd.read_pdbstr: cmd.alter(objname, '(ID,resi,segi)=' +\ '(ID+100000*int(segi[:2]), resv+10000*int(segi[2:]), "")') Cheers, Thomas On 08/18/2011 10:40 AM, Tsjerk Wassenaar wrote: > Hi Joseph, > > Sorry about that. A bit naive with the numbering. To fix it, change the function > > def pdbOut(atom,i=1): > return _pdbline%((i,) + (atom[0][:3],) + (atom[1],) + (atom[3],) + > (atom[2],) + atom[4:] + (1,40) + (atom[0][0],)) > > to > > def pdbOut(atom,i=1): > stuff = [i%1e5,atom[0][:3],atom[1],atom[3],atom[2]%1e4]+list(atom[4:])+[1,40,atom[0][0]] > return _pdbline % tuple(stuff) > > It worked for me on a .gro file with 160k atoms :) > > Cheers, > > Tsjerk > > 2011/8/18 Joseph André: >> Hi Tsjerk, >> Thanks for the script. It works great on my protein. However when I try to >> load the solvated system> 100.000 atoms I have problems with water >> molecules. Is it possible to handle gro files with more than 100.000 atoms >> and 9999 residues? >> Best -- Thomas Holder MPI for Developmental Biology ```
 Re: [PyMOL] loading gro files From: Michael Lerner - 2011-08-18 19:08:26 Attachments: Message as HTML ```On Thu, Aug 18, 2011 at 3:39 AM, Tsjerk Wassenaar wrote: > Hey :) > > Here is an all Python solution to load a .gro file, including the box > vectors. It simply converts to PDB format and calls cmd.read_pdbstr... > It supports multimodel files. I'll probably add a mechanism to > identify chains from breaks, as the .gro format does not use chain > identifiers, and may add gzip support. Later I'll also add MARTINI > coarse graining, while I'm at it :) > Do you have a fairly complete Python library for parsing GROMACS topology files? I tend to write ad hoc scripts that add CONECT records to MARTINI models. It's easy to do that for lipid bilayers, but I'd love a more general solution that makes it easy to load proteins correctly. Cheers, -Michael > > Hope it helps, > > Tsjerk > > > ### > > from pymol import cmd > import math > > _pdbline = "ATOM %5i %-3s %3s%2s%4i %8.3f%8.3f%8.3f%6.2f%6.2f > %1s \n" > _pdbBoxLine = "CRYST1%9.3f%9.3f%9.3f%7.2f%7.2f%7.2f P 1 1\n" > > d2r = math.pi/180 > > def cos_angle(a,b): > p = sum([i*j for i,j in zip(a,b)]) > q = math.sqrt(sum([i*i for i in a])*sum([j*j for j in b])) > return min(max(-1,p/q),1) > > def norm2(a): > return sum([i*i for i in a]) > > def norm(a): > return math.sqrt(norm2(a)) > > def groBoxRead(a): > b = [10*float(i) for i in a.split()] + 6*[0] # Padding for rectangular > boxes > return b[0],b[3],b[4],b[5],b[1],b[6],b[7],b[8],b[2] > > def groAtom(a): > #012345678901234567890123456789012345678901234567890 > # 1PRN N 1 4.168 11.132 5.291 > ## ===> atom name, res name, res id, chain > x, y, z > return (a[10:15].strip(),a[5:10].strip(),int(a[:5])," > ",10*float(a[20:28]),10*float(a[28:36]),10*float(a[36:44])) > > # Simple GRO iterator > def groFrameIterator(stream): > while True: > title = stream.readline() > natoms = stream.readline().strip() > if not natoms: > break > natoms = int(natoms) > atoms = [groAtom(stream.readline()) for i in range(natoms)] > box = groBoxRead(stream.readline()) > yield title, atoms, box > > def pdbOut(atom,i=1): > return _pdbline%((i,) + (atom[0][:3],) + (atom[1],) + (atom[3],) + > (atom[2],) + atom[4:] + (1,40) + (atom[0][0],)) > > def pdbBoxString(box): > nu = math.sqrt(norm2(box[0:3])) > nv = math.sqrt(norm2(box[3:6])) > nw = math.sqrt(norm2(box[6:9])) > > alpha = nv*nw == 0 and 90 or math.acos(cos_angle(box[3:6],box[6:9]))/d2r > beta = nu*nw == 0 and 90 or math.acos(cos_angle(box[0:3],box[6:9]))/d2r > gamma = nu*nv == 0 and 90 or math.acos(cos_angle(box[0:3],box[6:9]))/d2r > > return _pdbBoxLine % > (norm(box[0:3]),norm(box[3:6]),norm(box[6:9]),alpha,beta,gamma) > > def gro(filename): > objname = filename[1+filename.rfind("/"):filename.rfind(".")] > pdb = [] > model = 1 > for title, atoms, box in groFrameIterator(open(filename)): > pdb.append("MODEL %8d"%model) > pdb.append(pdbBoxString(box)) > pdb.extend([pdbOut(atom,i) for atom, i in > zip(atoms,range(1,len(atoms)+1))]) > pdb.append("ENDMDL") > model += 1 > cmd.read_pdbstr("\n".join(pdb),objname) > > cmd.extend("gro",gro) > > ### > > On Wed, Aug 17, 2011 at 5:11 AM, Jason Vertrees > wrote: > > Hi Michael, > > > > PyMOL knows about gromacs files, but needs to better handle .gro > > files, specifically. Currently you have to export to a PDB to read the > > topology. > > > > Please file this on the open-source tracker > > (https://sourceforge.net/tracker/?group_id=4546) and I'll get to it > > ASAP. > > > > Cheers, > > > > -- Jason > > > > On Mon, Aug 15, 2011 at 8:19 PM, Michael Daily > wrote: > >> Hi all, > >> > >> Is there a direct way to load a gromacs structure file (.gro) in PyMOL? > I > >> know it's simple to convert them to pdb using editconf, but I want to > load > >> gro files directly (as you can in vmd) because they permit higher max. > atom > >> and residue numbers (100K vs. 10K for pdb) and permit longer residue > names > >> (4 chars vs. 3 for vmd). > >> > >> Thanks, > >> Mike > >> > >> -- > >> ==================================== > >> Michael D. Daily > >> Postdoctoral research associate > >> Pacific Northwest National Lab (PNNL) > >> 509-375-4581 > >> (formerly Qiang Cui group, University of Wisconsin-Madison) > >> > >> > ------------------------------------------------------------------------------ > >> uberSVN's rich system and user administration capabilities and model > >> configuration take the hassle out of deploying and managing Subversion > and > >> the tools developers use with it. Learn more about uberSVN and get a > free > >> download at: http://p.sf.net/sfu/wandisco-dev2dev > >> > >> _______________________________________________ > >> PyMOL-users mailing list (PyMOL-users@...) > >> Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users > >> Archives: http://www.mail-archive.com/pymol-users@... > >> > > > > > > > > -- > > Jason Vertrees, PhD > > PyMOL Product Manager > > Schrodinger, LLC > > > > (e) Jason.Vertrees@... > > (o) +1 (603) 374-7120 > > > > > ------------------------------------------------------------------------------ > > Get a FREE DOWNLOAD! and learn more about uberSVN rich system, > > user administration capabilities and model configuration. Take > > the hassle out of deploying and managing Subversion and the > > tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2 > > _______________________________________________ > > PyMOL-users mailing list (PyMOL-users@...) > > Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users > > Archives: http://www.mail-archive.com/pymol-users@... > > > > > > -- > Tsjerk A. Wassenaar, Ph.D. > > post-doctoral researcher > Molecular Dynamics Group > * Groningen Institute for Biomolecular Research and Biotechnology > * Zernike Institute for Advanced Materials > University of Groningen > The Netherlands > > > ------------------------------------------------------------------------------ > Get a FREE DOWNLOAD! and learn more about uberSVN rich system, > user administration capabilities and model configuration. Take > the hassle out of deploying and managing Subversion and the > tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2 > _______________________________________________ > PyMOL-users mailing list (PyMOL-users@...) > Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users > Archives: http://www.mail-archive.com/pymol-users@... > -- Michael Lerner Department of Physics and Astronomy Earlham College - Drawer 111 801 National Road West Richmond, IN 47374-4095 ```
 Re: [PyMOL] loading gro files From: Tsjerk Wassenaar - 2011-08-18 19:43:00 ```Hi Michael, Proteins are actually very easy, because of the fixed connectivity... I'll post a few scripts soon to coarse grain a protein in Pymol, and to fix/show the connectivity. I'll have to combine some things from scriptlets here and there, though. Cheers, Tsjerk On Thu, Aug 18, 2011 at 9:07 PM, Michael Lerner wrote: > > > On Thu, Aug 18, 2011 at 3:39 AM, Tsjerk Wassenaar wrote: >> >> Hey :) >> >> Here is an all Python solution to load a .gro file, including the box >> vectors. It simply converts to PDB format and calls cmd.read_pdbstr... >> It supports multimodel files. I'll probably add a mechanism to >> identify chains from breaks, as the .gro format does not use chain >> identifiers, and may add gzip support. Later I'll also add MARTINI >> coarse graining, while I'm at it :) > > Do you have a fairly complete Python library for parsing GROMACS topology > files? I tend to write ad hoc scripts that add CONECT records to MARTINI > models. It's easy to do that for lipid bilayers, but I'd love a more general > solution that makes it easy to load proteins correctly. > Cheers, > -Michael > >> >> Hope it helps, >> >> Tsjerk >> >> >> ### >> >> from pymol import cmd >> import math >> >> _pdbline    = "ATOM  %5i  %-3s %3s%2s%4i    %8.3f%8.3f%8.3f%6.2f%6.2f >>         %1s  \n" >> _pdbBoxLine = "CRYST1%9.3f%9.3f%9.3f%7.2f%7.2f%7.2f P 1           1\n" >> >> d2r = math.pi/180 >> >> def cos_angle(a,b): >>    p = sum([i*j for i,j in zip(a,b)]) >>    q = math.sqrt(sum([i*i for i in a])*sum([j*j for j in b])) >>    return min(max(-1,p/q),1) >> >> def norm2(a): >>    return sum([i*i for i in a]) >> >> def norm(a): >>    return math.sqrt(norm2(a)) >> >> def groBoxRead(a): >>    b = [10*float(i) for i in a.split()] + 6*[0] # Padding for rectangular >> boxes >>    return b[0],b[3],b[4],b[5],b[1],b[6],b[7],b[8],b[2] >> >> def groAtom(a): >>    #012345678901234567890123456789012345678901234567890 >>    #    1PRN      N    1   4.168  11.132   5.291 >>    ## ===> atom name,       res name,       res id,    chain >> x,                 y,                 z >>    return (a[10:15].strip(),a[5:10].strip(),int(a[:5])," >> ",10*float(a[20:28]),10*float(a[28:36]),10*float(a[36:44])) >> >> # Simple GRO iterator >> def groFrameIterator(stream): >>    while True: >>        title = stream.readline() >>        natoms = stream.readline().strip() >>        if not natoms: >>            break >>        natoms = int(natoms) >>        atoms  = [groAtom(stream.readline())  for i in range(natoms)] >>        box    = groBoxRead(stream.readline()) >>        yield title, atoms, box >> >> def pdbOut(atom,i=1): >>    return _pdbline%((i,) + (atom[0][:3],) + (atom[1],) + (atom[3],) + >> (atom[2],) + atom[4:] + (1,40) + (atom[0][0],)) >> >> def pdbBoxString(box): >>    nu = math.sqrt(norm2(box[0:3])) >>    nv = math.sqrt(norm2(box[3:6])) >>    nw = math.sqrt(norm2(box[6:9])) >> >>    alpha = nv*nw == 0 and 90 or >> math.acos(cos_angle(box[3:6],box[6:9]))/d2r >>    beta  = nu*nw == 0 and 90 or >> math.acos(cos_angle(box[0:3],box[6:9]))/d2r >>    gamma = nu*nv == 0 and 90 or >> math.acos(cos_angle(box[0:3],box[6:9]))/d2r >> >>    return _pdbBoxLine % >> (norm(box[0:3]),norm(box[3:6]),norm(box[6:9]),alpha,beta,gamma) >> >> def gro(filename): >>    objname = filename[1+filename.rfind("/"):filename.rfind(".")] >>    pdb     = [] >>    model   = 1 >>    for title, atoms, box in groFrameIterator(open(filename)): >>        pdb.append("MODEL %8d"%model) >>        pdb.append(pdbBoxString(box)) >>        pdb.extend([pdbOut(atom,i) for atom, i in >> zip(atoms,range(1,len(atoms)+1))]) >>        pdb.append("ENDMDL") >>        model += 1 >>    cmd.read_pdbstr("\n".join(pdb),objname) >> >> cmd.extend("gro",gro) >> >> ### >> >> On Wed, Aug 17, 2011 at 5:11 AM, Jason Vertrees >> wrote: >> > Hi Michael, >> > >> > PyMOL knows about gromacs files, but needs to better handle .gro >> > files, specifically. Currently you have to export to a PDB to read the >> > topology. >> > >> > Please file this on the open-source tracker >> > (https://sourceforge.net/tracker/?group_id=4546) and I'll get to it >> > ASAP. >> > >> > Cheers, >> > >> > -- Jason >> > >> > On Mon, Aug 15, 2011 at 8:19 PM, Michael Daily >> > wrote: >> >> Hi all, >> >> >> >> Is there a direct way to load a gromacs structure file (.gro) in PyMOL? >> >> I >> >> know it's simple to convert them to pdb using editconf, but I want to >> >> load >> >> gro files directly (as you can in vmd) because they permit higher max. >> >> atom >> >> and residue numbers (100K vs. 10K for pdb) and permit longer residue >> >> names >> >> (4 chars vs. 3 for vmd). >> >> >> >> Thanks, >> >> Mike >> >> >> >> -- >> >> ==================================== >> >> Michael D. Daily >> >> Postdoctoral research associate >> >> Pacific Northwest National Lab (PNNL) >> >> 509-375-4581 >> >> (formerly Qiang Cui group, University of Wisconsin-Madison) >> >> >> >> >> >> ------------------------------------------------------------------------------ >> >> uberSVN's rich system and user administration capabilities and model >> >> configuration take the hassle out of deploying and managing Subversion >> >> and >> >> the tools developers use with it. Learn more about uberSVN and get a >> >> free >> >> download at:  http://p.sf.net/sfu/wandisco-dev2dev >> >> >> >> _______________________________________________ >> >> PyMOL-users mailing list (PyMOL-users@...) >> >> Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users >> >> Archives: http://www.mail-archive.com/pymol-users@... >> >> >> > >> > >> > >> > -- >> > Jason Vertrees, PhD >> > PyMOL Product Manager >> > Schrodinger, LLC >> > >> > (e) Jason.Vertrees@... >> > (o) +1 (603) 374-7120 >> > >> > >> > ------------------------------------------------------------------------------ >> > Get a FREE DOWNLOAD! and learn more about uberSVN rich system, >> > user administration capabilities and model configuration. Take >> > the hassle out of deploying and managing Subversion and the >> > tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2 >> > _______________________________________________ >> > PyMOL-users mailing list (PyMOL-users@...) >> > Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users >> > Archives: http://www.mail-archive.com/pymol-users@... >> > >> >> >> >> -- >> Tsjerk A. Wassenaar, Ph.D. >> >> post-doctoral researcher >> Molecular Dynamics Group >> * Groningen Institute for Biomolecular Research and Biotechnology >> * Zernike Institute for Advanced Materials >> University of Groningen >> The Netherlands >> >> >> ------------------------------------------------------------------------------ >> Get a FREE DOWNLOAD! and learn more about uberSVN rich system, >> user administration capabilities and model configuration. Take >> the hassle out of deploying and managing Subversion and the >> tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2 >> _______________________________________________ >> PyMOL-users mailing list (PyMOL-users@...) >> Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users >> Archives: http://www.mail-archive.com/pymol-users@... > > > > -- > Michael Lerner > Department of Physics and Astronomy > Earlham College - Drawer 111 > 801 National Road West > Richmond, IN   47374-4095 > -- Tsjerk A. Wassenaar, Ph.D. post-doctoral researcher Molecular Dynamics Group * Groningen Institute for Biomolecular Research and Biotechnology * Zernike Institute for Advanced Materials University of Groningen The Netherlands ```