Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project!

## Re: [PyMOL] Distances and Python scripts

 Re: [PyMOL] Distances and Python scripts From: Andreas Henschel - 2007-06-18 13:38:11 ```Hi Xavier, here is a naive approach to solve problem 2), which should include your first problem. ######################################################################### from pymol import cmd, stored ## setup myProt = "2gsm" mySegm = "" myChain = "B" cmd.fetch(myProt) outfile = open("/tmp/n_n_distances.txt", "w") selection = "/%s/%s/%s/*/N" % (myProt, mySegm, myChain) ## getting the atoms of a selection stored.list = [] cmd.iterate(selection, "stored.list.append((resi, name))") print len(stored.list) for atom1 in stored.list: for atom2 in stored.list: selection1 = "/%s/%s/%s/%s/%s" % (myProt, mySegm, myChain, atom1[0], atom1[1]) selection2 = "/%s/%s/%s/%s/%s" % (myProt, mySegm, myChain, atom2[0], atom2[1]) distance = cmd.distance("d", selection1, selection2, cutoff = 6.0) if distance > 0.0: ## distance can be 0, if atom1==atom2 or if atom1 and atom2 are more than 6A apart print >> outfile, selection1, selection2, distance outfile.close() ######################################################################## produces a file like this: ## /2gsm//B/31/N /2gsm//B/30/N 3.59292006493 ## /2gsm//B/31/N /2gsm//B/32/N 3.55046916008 ## /2gsm//B/31/N /2gsm//B/246/N 5.16704130173 I hope perfomance doesnt matter, since this is quite slow. Otherwise I suggest to use get_model to get a list of coordinates and put them into a distance matrix, eg. using scipy: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498246 let me know if this is what you want. I hope that helps! Best regards, Andreas Xavier HANOULLE wrote: > Hi all, > > I have 2 problems regarding the distance command and python scripting: > > *1/* I would like to use a script in order to print in a file the > results of this following command: > distance dist6, (/MyProt/MyProt/A/181/N), (/MyProt/MyProt/A/*/N), 6.0 > This command displays distances and dash lines between the N atom of > residue 181 and all the N atoms of MyProt which are at <6Ang. How do I > have to write a Python script to get the results in a text file that > will look like: > /MyProt/MyProt/A/181/N /MyProt/MyProt/A/180/ 4.856 > /MyProt/MyProt/A/181/N /MyProt/MyProt/A/182/ 3.956 > /MyProt/MyProt/A/181/N /MyProt/MyProt/A/78/ 5.562 > /MyProt/MyProt/A/181/N /MyProt/MyProt/A/105/ 2.863 > ... ? > > > *2/ *How do I have to write a python script to measure all the N-N > distances in my protein and to print the results in a text file that > will look like: > /MyProt/MyProt/A/1/N /MyProt/MyProt/A/2/ 4.856 > /MyProt/MyProt/A/1/N /MyProt/MyProt/A/3/ 3.956 > /MyProt/MyProt/A/1/N /MyProt/MyProt/A/4/ 5.562 > ... > /MyProt/MyProt/A/2/N /MyProt/MyProt/A/1/ 3.857 > /MyProt/MyProt/A/2/N /MyProt/MyProt/A/3/ 7.249 > /MyProt/MyProt/A/2/N /MyProt/MyProt/A/4/ 8.762 > ... ? > Furthermore, would it be possible to add a limit for these distances ? > For exemple, only get the N-N distances in MyProt which are <7Ang. ? > > Thanks for your help. > Sincerely, > > Xavier. > > * > ------------------------------------------------------------------------ > * > > *Xavier HANOULLE, Ph.D.* > > UMR 8576 CNRS–USTL > Structural and Functional Glycobiology Unit > NMR Laboratory > 59655 Villeneuve d’Ascq Cedex - France > > Phone: +33 (0)3.20.33.72.41 > E-mail : xavier.hanoulle@... > > www: http://groupe-rmn-modelisation.univ-lille1.fr > ; > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > ------------------------------------------------------------------------ > > _______________________________________________ > PyMOL-users mailing list > PyMOL-users@... > https://lists.sourceforge.net/lists/listinfo/pymol-users > -- Andreas Henschel Bioinformatics Group TU Dresden Tatzberg 47-51 01307 Dresden, Germany Phone: +49 351 463 40063 EMail: ah@... ```

 [PyMOL] Distances and Python scripts From: Xavier HANOULLE - 2007-06-18 09:42:50 ``` Hi all,

I have 2 problems regarding the distance command and python scripting:

1/ I would like to use a script in order to print in a file the results of this following command:
distance dist6, (/MyProt/MyProt/A/181/N), (/MyProt/MyProt/A/*/N), 6.0
This command displays distances and dash lines between
the N atom of residue 181 and all the N atoms of MyProt which are at <6Ang. How do I have to write a Python script to get the results in a text file that will look like:
/MyProt/MyProt/A/181/N
/MyProt/MyProt/A/180/       4.856
/
MyProt/MyProt/A/181/N   /MyProt/MyProt/A/182/       3.956
/
MyProt/MyProt/A/181/N   /MyProt/MyProt/A/78/         5.562

/MyProt/MyProt/A/181/N   /MyProt/MyProt/A/105/       2.863
... ?

2/ How do I have to write a python script to measure all the N-N distances in my protein and to print the results in a text file that will look like:

/MyProt/MyProt/A/1/N   /MyProt/MyProt/A/2/       4.856
/
MyProt/MyProt/A/1/N   /MyProt/MyProt/A/3/       3.956
/
MyProt/MyProt/A/1/N   /MyProt/MyProt/A/4/       5.562
...
/MyProt/MyProt/A/2/N   /MyProt/MyProt/A/1/       3.857
/
MyProt/MyProt/A/2/N   /MyProt/MyProt/A/3/       7.249
/
MyProt/MyProt/A/2/N   /MyProt/MyProt/A/4/       8.762
... ?
Furthermore, would it be possible to add a limit for these distances ? For exemple, only get the N-N distances in MyProt which are <7Ang. ?

Sincerely,

Xavier.

Xavier HANOULLE, Ph.D.

UMR 8576 CNRS–USTL
Structural and Functional Glycobiology Unit
NMR Laboratory
59655 Villeneuve d’Ascq Cedex - France

Phone: +33 (0)3.20.33.72.41
E-mail : xavier.hanoulle@...
www: http://groupe-rmn-modelisation.univ-lille1.fr

```
 Re: [PyMOL] Distances and Python scripts From: Andreas Henschel - 2007-06-18 13:38:11 ```Hi Xavier, here is a naive approach to solve problem 2), which should include your first problem. ######################################################################### from pymol import cmd, stored ## setup myProt = "2gsm" mySegm = "" myChain = "B" cmd.fetch(myProt) outfile = open("/tmp/n_n_distances.txt", "w") selection = "/%s/%s/%s/*/N" % (myProt, mySegm, myChain) ## getting the atoms of a selection stored.list = [] cmd.iterate(selection, "stored.list.append((resi, name))") print len(stored.list) for atom1 in stored.list: for atom2 in stored.list: selection1 = "/%s/%s/%s/%s/%s" % (myProt, mySegm, myChain, atom1[0], atom1[1]) selection2 = "/%s/%s/%s/%s/%s" % (myProt, mySegm, myChain, atom2[0], atom2[1]) distance = cmd.distance("d", selection1, selection2, cutoff = 6.0) if distance > 0.0: ## distance can be 0, if atom1==atom2 or if atom1 and atom2 are more than 6A apart print >> outfile, selection1, selection2, distance outfile.close() ######################################################################## produces a file like this: ## /2gsm//B/31/N /2gsm//B/30/N 3.59292006493 ## /2gsm//B/31/N /2gsm//B/32/N 3.55046916008 ## /2gsm//B/31/N /2gsm//B/246/N 5.16704130173 I hope perfomance doesnt matter, since this is quite slow. Otherwise I suggest to use get_model to get a list of coordinates and put them into a distance matrix, eg. using scipy: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498246 let me know if this is what you want. I hope that helps! Best regards, Andreas Xavier HANOULLE wrote: > Hi all, > > I have 2 problems regarding the distance command and python scripting: > > *1/* I would like to use a script in order to print in a file the > results of this following command: > distance dist6, (/MyProt/MyProt/A/181/N), (/MyProt/MyProt/A/*/N), 6.0 > This command displays distances and dash lines between the N atom of > residue 181 and all the N atoms of MyProt which are at <6Ang. How do I > have to write a Python script to get the results in a text file that > will look like: > /MyProt/MyProt/A/181/N /MyProt/MyProt/A/180/ 4.856 > /MyProt/MyProt/A/181/N /MyProt/MyProt/A/182/ 3.956 > /MyProt/MyProt/A/181/N /MyProt/MyProt/A/78/ 5.562 > /MyProt/MyProt/A/181/N /MyProt/MyProt/A/105/ 2.863 > ... ? > > > *2/ *How do I have to write a python script to measure all the N-N > distances in my protein and to print the results in a text file that > will look like: > /MyProt/MyProt/A/1/N /MyProt/MyProt/A/2/ 4.856 > /MyProt/MyProt/A/1/N /MyProt/MyProt/A/3/ 3.956 > /MyProt/MyProt/A/1/N /MyProt/MyProt/A/4/ 5.562 > ... > /MyProt/MyProt/A/2/N /MyProt/MyProt/A/1/ 3.857 > /MyProt/MyProt/A/2/N /MyProt/MyProt/A/3/ 7.249 > /MyProt/MyProt/A/2/N /MyProt/MyProt/A/4/ 8.762 > ... ? > Furthermore, would it be possible to add a limit for these distances ? > For exemple, only get the N-N distances in MyProt which are <7Ang. ? > > Thanks for your help. > Sincerely, > > Xavier. > > * > ------------------------------------------------------------------------ > * > > *Xavier HANOULLE, Ph.D.* > > UMR 8576 CNRS–USTL > Structural and Functional Glycobiology Unit > NMR Laboratory > 59655 Villeneuve d’Ascq Cedex - France > > Phone: +33 (0)3.20.33.72.41 > E-mail : xavier.hanoulle@... > > www: http://groupe-rmn-modelisation.univ-lille1.fr > ; > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > ------------------------------------------------------------------------ > > _______________________________________________ > PyMOL-users mailing list > PyMOL-users@... > https://lists.sourceforge.net/lists/listinfo/pymol-users > -- Andreas Henschel Bioinformatics Group TU Dresden Tatzberg 47-51 01307 Dresden, Germany Phone: +49 351 463 40063 EMail: ah@... ```