Re: [PyMOL] command question RE printing out distances to text file
Another follow up question to this. I decided to use the measure distance python script on the pymol wiki to do this, and I was able to do it successfully with a range of residues, but my question is about the output txt file. When I run the script I get the correct distances (all 3 of them) to show on the GUI but the text file that is generated (distnew.txt) only lists one distance--so perhaps the script needs to be modified for this as well for the residues measured? The original script is at the link http://www.pymolwiki.org/index.php/Measure_Distance and my modified version is below. Suggestions appreciated! Thank you. # This script writes the distance from # atom mol1///25/ha to atom mol1///26/ha # out to the file dist.txt # Simply change your selections to see different distances. # import PyMOL's command namespace from pymol import cmd # open dist.txt for writing f=open('distnew.txt','w') # calculate the distance and store it in dst dst=cmd.distance('tmp','B///297/cb','A///17-19/cb') # write the formatted value of the distance (dst) # to the output file f.write(%8.3f\n%dst) # close the output file. f.close() From: Robert Campbell [robert.campb...@queensu.ca] Sent: Monday, June 09, 2014 10:04 AM To: pymol-users@lists.sourceforge.net Subject: Re: [PyMOL] command question RE printing out distances to text file Hi Suzanne, You can also get the distance printed in the external GUI or terminal window by using the cmd.distance version of the command. So either you can assign the distance to a variable and print it or you can print the result directly. Assuming you have two selections, sele1 and sele2 specifying the atoms of interest you can do: d = cmd.distance(sele1,sele2) print sele1,sele2,d Cheers, Rob On Mon, 2014-06-09 13:13 EDT, Thomas Holder thomas.hol...@schrodinger.com wrote: Hi Suzanne, you can use the get_distance command. It doesn't generate a distance object but prints the distance to the external window. https://urldefense.proofpoint.com/v1/url?u=http://pymolwiki.org/index.php/Get_Distancek=7DHVT22D9IhC0F3WohFMBA%3D%3D%0Ar=1ciN0EuZ9XNq3lPnYtgkI5sKPXgKVaywidBN0C981SQ%3D%0Am=fr2bAoLQoVgp9h2t2fgBvfGVVX7oQ1g14g1AODFz%2FRg%3D%0As=921f4dfed39cd38f4ae7a70dfb937844d4e3faf1bc967c2f4d1f2944fa2ea31b Cheers, Thomas On 06 Jun 2014, at 23:03, Lapolla, Suzanne M (HSC) suzanne-lapo...@ouhsc.edu wrote: Fellow Pymol Users: I may have asked this question before...but if so have forgotten. I am measuring distances between 2 atoms in 2 different objects using the distance command, and it is working perfectly, but I wonder if there is a command I can use/add so that those distances can be printed in the external gui as well as being shown in the viewer. I will be doing lots of these at the same time and the screen will get crowded. Thank you in advance. -- Robert L. Campbell, Ph.D. Senior Research Associate/Adjunct Assistant Professor Dept. of Biomedical Molecular Sciences Botterell Hall Rm 644 Queen's University, Kingston, ON K7L 3N6 Canada Tel: 613-533-6821 robert.campb...@queensu.ca https://urldefense.proofpoint.com/v1/url?u=http://pldserver1.biochem.queensu.ca/~rlck=7DHVT22D9IhC0F3WohFMBA%3D%3D%0Ar=1ciN0EuZ9XNq3lPnYtgkI5sKPXgKVaywidBN0C981SQ%3D%0Am=fr2bAoLQoVgp9h2t2fgBvfGVVX7oQ1g14g1AODFz%2FRg%3D%0As=aaad7877cf1640401ae708b7b5f5a2fbe03abec4d2f0ef509e7360c0017ee225 -- HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions Find What Matters Most in Your Big Data with HPCC Systems Open Source. Fast. Scalable. Simple. Ideal for Dirty Data. Leverages Graph Analysis for Fast Processing Easy Data Exploration https://urldefense.proofpoint.com/v1/url?u=http://www.hpccsystems.com/k=7DHVT22D9IhC0F3WohFMBA%3D%3D%0Ar=1ciN0EuZ9XNq3lPnYtgkI5sKPXgKVaywidBN0C981SQ%3D%0Am=fr2bAoLQoVgp9h2t2fgBvfGVVX7oQ1g14g1AODFz%2FRg%3D%0As=dabd029c6435c0bbe92d916555213bd7ccbd3d4ac6dcf2de28cf19c428ff0eed ___ PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net) Info Page: https://urldefense.proofpoint.com/v1/url?u=https://lists.sourceforge.net/lists/listinfo/pymol-usersk=7DHVT22D9IhC0F3WohFMBA%3D%3D%0Ar=1ciN0EuZ9XNq3lPnYtgkI5sKPXgKVaywidBN0C981SQ%3D%0Am=fr2bAoLQoVgp9h2t2fgBvfGVVX7oQ1g14g1AODFz%2FRg%3D%0As=6e6df3376d82f34b3bce9c1de38053ec6052ce7313087062131127d0c0c03fb7 Archives: https://urldefense.proofpoint.com/v1/url?u=http://www.mail-archive.com/pymol-users%40lists.sourceforge.netk=7DHVT22D9IhC0F3WohFMBA%3D%3D%0Ar=1ciN0EuZ9XNq3lPnYtgkI5sKPXgKVaywidBN0C981SQ%3D%0Am=fr2bAoLQoVgp9h2t2fgBvfGVVX7oQ1g14g1AODFz%2FRg%3D%0As=f7df11447d13070db8093ed0604c19654bebcf07d28d46919253043bb5dbe80e -- HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions Find What Matters Most in Your Big Data with
Re: [PyMOL] command question RE printing out distances to text file
Hej Suzanne, you will need to append the other two distances to the script to get them printed. Following your example that would be something like: # calculate the distance and store it in dst dst1=cmd.distance('tmp','B///297/cb','A///17-19/cb') dst2=cmd.distance('tmp','B///297/cb','A///17-19/cb') # change the selections in this line! dst3=cmd.distance('tmp','B///297/cb','A///17-19/cb') # change the selections in this line! # and then for writing the output file f.write(%8.3f\n%dst1) f.write(%8.3f\n%dst2) f.write(%8.3f\n%dst3) inserting these blocks in your script hopefully will do the trick. Cheers, Andreas On Tue, Jun 17, 2014 at 8:21 PM, Lapolla, Suzanne M (HSC) suzanne-lapo...@ouhsc.edu wrote: Another follow up question to this. I decided to use the measure distance python script on the pymol wiki to do this, and I was able to do it successfully with a range of residues, but my question is about the output txt file. When I run the script I get the correct distances (all 3 of them) to show on the GUI but the text file that is generated (distnew.txt) only lists one distance--so perhaps the script needs to be modified for this as well for the residues measured? The original script is at the link http://www.pymolwiki.org/index.php/Measure_Distance and my modified version is below. Suggestions appreciated! Thank you. # This script writes the distance from # atom mol1///25/ha to atom mol1///26/ha # out to the file dist.txt # Simply change your selections to see different distances. # import PyMOL's command namespace from pymol import cmd # open dist.txt for writing f=open('distnew.txt','w') # calculate the distance and store it in dst dst=cmd.distance('tmp','B///297/cb','A///17-19/cb') # write the formatted value of the distance (dst) # to the output file f.write(%8.3f\n%dst) # close the output file. f.close() From: Robert Campbell [robert.campb...@queensu.ca] Sent: Monday, June 09, 2014 10:04 AM To: pymol-users@lists.sourceforge.net Subject: Re: [PyMOL] command question RE printing out distances to text file Hi Suzanne, You can also get the distance printed in the external GUI or terminal window by using the cmd.distance version of the command. So either you can assign the distance to a variable and print it or you can print the result directly. Assuming you have two selections, sele1 and sele2 specifying the atoms of interest you can do: d = cmd.distance(sele1,sele2) print sele1,sele2,d Cheers, Rob On Mon, 2014-06-09 13:13 EDT, Thomas Holder thomas.hol...@schrodinger.com wrote: Hi Suzanne, you can use the get_distance command. It doesn't generate a distance object but prints the distance to the external window. https://urldefense.proofpoint.com/v1/url?u=http://pymolwiki.org/index.php/Get_Distancek=7DHVT22D9IhC0F3WohFMBA%3D%3D%0Ar=1ciN0EuZ9XNq3lPnYtgkI5sKPXgKVaywidBN0C981SQ%3D%0Am=fr2bAoLQoVgp9h2t2fgBvfGVVX7oQ1g14g1AODFz%2FRg%3D%0As=921f4dfed39cd38f4ae7a70dfb937844d4e3faf1bc967c2f4d1f2944fa2ea31b Cheers, Thomas On 06 Jun 2014, at 23:03, Lapolla, Suzanne M (HSC) suzanne-lapo...@ouhsc.edu wrote: Fellow Pymol Users: I may have asked this question before...but if so have forgotten. I am measuring distances between 2 atoms in 2 different objects using the distance command, and it is working perfectly, but I wonder if there is a command I can use/add so that those distances can be printed in the external gui as well as being shown in the viewer. I will be doing lots of these at the same time and the screen will get crowded. Thank you in advance. -- Robert L. Campbell, Ph.D. Senior Research Associate/Adjunct Assistant Professor Dept. of Biomedical Molecular Sciences Botterell Hall Rm 644 Queen's University, Kingston, ON K7L 3N6 Canada Tel: 613-533-6821 robert.campb...@queensu.ca https://urldefense.proofpoint.com/v1/url?u=http://pldserver1.biochem.queensu.ca/~rlck=7DHVT22D9IhC0F3WohFMBA%3D%3D%0Ar=1ciN0EuZ9XNq3lPnYtgkI5sKPXgKVaywidBN0C981SQ%3D%0Am=fr2bAoLQoVgp9h2t2fgBvfGVVX7oQ1g14g1AODFz%2FRg%3D%0As=aaad7877cf1640401ae708b7b5f5a2fbe03abec4d2f0ef509e7360c0017ee225 -- HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions Find What Matters Most in Your Big Data with HPCC Systems Open Source. Fast. Scalable. Simple. Ideal for Dirty Data. Leverages Graph Analysis for Fast Processing Easy Data Exploration https://urldefense.proofpoint.com/v1/url?u=http://www.hpccsystems.com/k=7DHVT22D9IhC0F3WohFMBA%3D%3D%0Ar=1ciN0EuZ9XNq3lPnYtgkI5sKPXgKVaywidBN0C981SQ%3D%0Am=fr2bAoLQoVgp9h2t2fgBvfGVVX7oQ1g14g1AODFz%2FRg%3D%0As=dabd029c6435c0bbe92d916555213bd7ccbd3d4ac6dcf2de28cf19c428ff0eed ___ PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net) Info Page:
Re: [PyMOL] command question RE printing out distances to text file
One more addition to the reply: I failed to notice that you are trying to input a range of residues '17-19' Make sure to input single atom selections to get correct distances and not an average: A straightforward way to get that name is to click on the atom while in the 'editing mode' of pymol: pymol will print: you clicked followed by a name that can be copy-pasted. e.g. You clicked /lys///LYS`2/CA - (pk1) can be used to copy-paste /lys///LYS`2/CA Another alternative is to use selections to identify one atom: e.g. cmd.distance('chain B and resi 297 and name CB','chain A and resi 17 and name CB') Then your example becomes: from pymol import cmd # open dist.txt for writing f=open('distnew.txt','w') # calculate the distance and store it in dst dst1=cmd.distance('chain B and resi 297 and name CB','chain A and resi 17 and name CB') dst2=cmd.distance('chain B and resi 297 and name CB','chain A and resi 18 and name CB') dst3=cmd.distance('chain B and resi 297 and name CB','chain A and resi 19 and name CB') # and then for writing the output file f.write(%8.3f\n%dst1) f.write(%8.3f\n%dst2) f.write(%8.3f\n%dst3) f.close() Cheers, Andreas On Tue, Jun 17, 2014 at 8:45 PM, Andreas Warnecke 4ndreas.warne...@gmail.com wrote: Hej Suzanne, you will need to append the other two distances to the script to get them printed. Following your example that would be something like: # calculate the distance and store it in dst dst1=cmd.distance('tmp','B///297/cb','A///17-19/cb') dst2=cmd.distance('tmp','B///297/cb','A///17-19/cb') # change the selections in this line! dst3=cmd.distance('tmp','B///297/cb','A///17-19/cb') # change the selections in this line! # and then for writing the output file f.write(%8.3f\n%dst1) f.write(%8.3f\n%dst2) f.write(%8.3f\n%dst3) inserting these blocks in your script hopefully will do the trick. Cheers, Andreas On Tue, Jun 17, 2014 at 8:21 PM, Lapolla, Suzanne M (HSC) suzanne-lapo...@ouhsc.edu wrote: Another follow up question to this. I decided to use the measure distance python script on the pymol wiki to do this, and I was able to do it successfully with a range of residues, but my question is about the output txt file. When I run the script I get the correct distances (all 3 of them) to show on the GUI but the text file that is generated (distnew.txt) only lists one distance--so perhaps the script needs to be modified for this as well for the residues measured? The original script is at the link http://www.pymolwiki.org/index.php/Measure_Distance and my modified version is below. Suggestions appreciated! Thank you. # This script writes the distance from # atom mol1///25/ha to atom mol1///26/ha # out to the file dist.txt # Simply change your selections to see different distances. # import PyMOL's command namespace from pymol import cmd # open dist.txt for writing f=open('distnew.txt','w') # calculate the distance and store it in dst dst=cmd.distance('tmp','B///297/cb','A///17-19/cb') # write the formatted value of the distance (dst) # to the output file f.write(%8.3f\n%dst) # close the output file. f.close() From: Robert Campbell [robert.campb...@queensu.ca] Sent: Monday, June 09, 2014 10:04 AM To: pymol-users@lists.sourceforge.net Subject: Re: [PyMOL] command question RE printing out distances to text file Hi Suzanne, You can also get the distance printed in the external GUI or terminal window by using the cmd.distance version of the command. So either you can assign the distance to a variable and print it or you can print the result directly. Assuming you have two selections, sele1 and sele2 specifying the atoms of interest you can do: d = cmd.distance(sele1,sele2) print sele1,sele2,d Cheers, Rob On Mon, 2014-06-09 13:13 EDT, Thomas Holder thomas.hol...@schrodinger.com wrote: Hi Suzanne, you can use the get_distance command. It doesn't generate a distance object but prints the distance to the external window. https://urldefense.proofpoint.com/v1/url?u=http://pymolwiki.org/index.php/Get_Distancek=7DHVT22D9IhC0F3WohFMBA%3D%3D%0Ar=1ciN0EuZ9XNq3lPnYtgkI5sKPXgKVaywidBN0C981SQ%3D%0Am=fr2bAoLQoVgp9h2t2fgBvfGVVX7oQ1g14g1AODFz%2FRg%3D%0As=921f4dfed39cd38f4ae7a70dfb937844d4e3faf1bc967c2f4d1f2944fa2ea31b Cheers, Thomas On 06 Jun 2014, at 23:03, Lapolla, Suzanne M (HSC) suzanne-lapo...@ouhsc.edu wrote: Fellow Pymol Users: I may have asked this question before...but if so have forgotten. I am measuring distances between 2 atoms in 2 different objects using the distance command, and it is working perfectly, but I wonder if there is a command I can use/add so that those distances can be printed in the external gui as well as being shown in the viewer. I will be doing lots of these at the same time and the screen will get crowded. Thank you in advance. -- Robert L. Campbell, Ph.D. Senior Research
Re: [PyMOL] command question RE printing out distances to text file
Ah I see--I will try and let you know how it works. Thanks again! From: Andreas Warnecke [4ndreas.warne...@gmail.com] Sent: Tuesday, June 17, 2014 2:18 PM To: Lapolla, Suzanne M (HSC) Cc: Robert Campbell; pymol-users@lists.sourceforge.net Subject: Re: [PyMOL] command question RE printing out distances to text file One more addition to the reply: I failed to notice that you are trying to input a range of residues '17-19' Make sure to input single atom selections to get correct distances and not an average: A straightforward way to get that name is to click on the atom while in the 'editing mode' of pymol: pymol will print: you clicked followed by a name that can be copy-pasted. e.g. You clicked /lys///LYS`2/CA - (pk1) can be used to copy-paste /lys///LYS`2/CA Another alternative is to use selections to identify one atom: e.g. cmd.distance('chain B and resi 297 and name CB','chain A and resi 17 and name CB') Then your example becomes: from pymol import cmd # open dist.txt for writing f=open('distnew.txt','w') # calculate the distance and store it in dst dst1=cmd.distance('chain B and resi 297 and name CB','chain A and resi 17 and name CB') dst2=cmd.distance('chain B and resi 297 and name CB','chain A and resi 18 and name CB') dst3=cmd.distance('chain B and resi 297 and name CB','chain A and resi 19 and name CB') # and then for writing the output file f.write(%8.3f\n%dst1) f.write(%8.3f\n%dst2) f.write(%8.3f\n%dst3) f.close() Cheers, Andreas On Tue, Jun 17, 2014 at 8:45 PM, Andreas Warnecke 4ndreas.warne...@gmail.commailto:4ndreas.warne...@gmail.com wrote: Hej Suzanne, you will need to append the other two distances to the script to get them printed. Following your example that would be something like: # calculate the distance and store it in dst dst1=cmd.distance('tmp','B///297/cb','A///17-19/cb') dst2=cmd.distance('tmp','B///297/cb','A///17-19/cb') # change the selections in this line! dst3=cmd.distance('tmp','B///297/cb','A///17-19/cb') # change the selections in this line! # and then for writing the output file f.write(%8.3f\n%dst1) f.write(%8.3f\n%dst2) f.write(%8.3f\n%dst3) inserting these blocks in your script hopefully will do the trick. Cheers, Andreas On Tue, Jun 17, 2014 at 8:21 PM, Lapolla, Suzanne M (HSC) suzanne-lapo...@ouhsc.edumailto:suzanne-lapo...@ouhsc.edu wrote: Another follow up question to this. I decided to use the measure distance python script on the pymol wiki to do this, and I was able to do it successfully with a range of residues, but my question is about the output txt file. When I run the script I get the correct distances (all 3 of them) to show on the GUI but the text file that is generated (distnew.txt) only lists one distance--so perhaps the script needs to be modified for this as well for the residues measured? The original script is at the link http://www.pymolwiki.org/index.php/Measure_Distancehttps://urldefense.proofpoint.com/v1/url?u=http://www.pymolwiki.org/index.php/Measure_Distancek=7DHVT22D9IhC0F3WohFMBA%3D%3D%0Ar=1ciN0EuZ9XNq3lPnYtgkI5sKPXgKVaywidBN0C981SQ%3D%0Am=EqubiL9cuYdYV13TK4bGte5vmf3Plq1xmWomVmdYlKU%3D%0As=992466ee53608d828281d0abbd95dc2742e6c75173eb93ae511f357e3225548b and my modified version is below. Suggestions appreciated! Thank you. # This script writes the distance from # atom mol1///25/ha to atom mol1///26/ha # out to the file dist.txt # Simply change your selections to see different distances. # import PyMOL's command namespace from pymol import cmd # open dist.txt for writing f=open('distnew.txt','w') # calculate the distance and store it in dst dst=cmd.distance('tmp','B///297/cb','A///17-19/cb') # write the formatted value of the distance (dst) # to the output file f.write(%8.3f\n%dst) # close the output file. f.close() From: Robert Campbell [robert.campb...@queensu.camailto:robert.campb...@queensu.ca] Sent: Monday, June 09, 2014 10:04 AM To: pymol-users@lists.sourceforge.netmailto:pymol-users@lists.sourceforge.net Subject: Re: [PyMOL] command question RE printing out distances to text file Hi Suzanne, You can also get the distance printed in the external GUI or terminal window by using the cmd.distance version of the command. So either you can assign the distance to a variable and print it or you can print the result directly. Assuming you have two selections, sele1 and sele2 specifying the atoms of interest you can do: d = cmd.distance(sele1,sele2) print sele1,sele2,d Cheers, Rob On Mon, 2014-06-09 13:13 EDT, Thomas Holder thomas.hol...@schrodinger.commailto:thomas.hol...@schrodinger.com wrote: Hi Suzanne, you can use the get_distance command. It doesn't generate a distance object but prints the distance to the external window.
Re: [PyMOL] command question RE printing out distances to text file
Hi Suzanne - The reason you have been getting only one distance in your output file is that your script is opening the file in “write” mode: f=open('distnew.txt','w') This will overwrite the contents of distnew.txt each time the script is run. If you want to keep all the distances without changing the rest of your script, you could open the file in “append” mode. f=open('distnew.txt',’a’) This way, each line will just get added to the bottom of the script. Keep in mind that if you want to start over with a new list of distances, you’ll need either to change the filename that gets opened (as you’ve done with “distnew.txt”) or delete the existing file. For this reason, I would go with one of the other approaches mentioned by Andreas, or look into using a list to define the atoms to which you’d like to measure the distance from the first atom, and loop through that list. Perhaps something like this (untested) bit of script would be useful, especially if you have many different atoms to check: first_atom = 'B///297/cb' second_atoms_list = ['A///17/cb', 'A///18/cb', 'A///19/cb'] with open(dist.txt, 'w') as f: for second_atom in second_atoms_list: f.write(%8.3f\n % cmd.distance(tmp, first_atom, second_atom)) Good luck! Cheers, Jared On Jun 17, 2014, at 2:21 PM, Lapolla, Suzanne M (HSC) suzanne-lapo...@ouhsc.edumailto:suzanne-lapo...@ouhsc.edu wrote: Another follow up question to this. I decided to use the measure distance python script on the pymol wiki to do this, and I was able to do it successfully with a range of residues, but my question is about the output txt file. When I run the script I get the correct distances (all 3 of them) to show on the GUI but the text file that is generated (distnew.txt) only lists one distance--so perhaps the script needs to be modified for this as well for the residues measured? The original script is at the link http://www.pymolwiki.org/index.php/Measure_Distance and my modified version is below. Suggestions appreciated! Thank you. # This script writes the distance from # atom mol1///25/ha to atom mol1///26/ha # out to the file dist.txt # Simply change your selections to see different distances. # import PyMOL's command namespace from pymol import cmd # open dist.txt for writing f=open('distnew.txt','w') # calculate the distance and store it in dst dst=cmd.distance('tmp','B///297/cb','A///17-19/cb') # write the formatted value of the distance (dst) # to the output file f.write(%8.3f\n%dst) # close the output file. f.close() From: Robert Campbell [robert.campb...@queensu.camailto:robert.campb...@queensu.ca] Sent: Monday, June 09, 2014 10:04 AM To: pymol-users@lists.sourceforge.netmailto:pymol-users@lists.sourceforge.net Subject: Re: [PyMOL] command question RE printing out distances to text file Hi Suzanne, You can also get the distance printed in the external GUI or terminal window by using the cmd.distance version of the command. So either you can assign the distance to a variable and print it or you can print the result directly. Assuming you have two selections, sele1 and sele2 specifying the atoms of interest you can do: d = cmd.distance(sele1,sele2) print sele1,sele2,d Cheers, Rob On Mon, 2014-06-09 13:13 EDT, Thomas Holder thomas.hol...@schrodinger.commailto:thomas.hol...@schrodinger.com wrote: Hi Suzanne, you can use the get_distance command. It doesn't generate a distance object but prints the distance to the external window. https://urldefense.proofpoint.com/v1/url?u=http://pymolwiki.org/index.php/Get_Distancek=7DHVT22D9IhC0F3WohFMBA%3D%3D%0Ar=1ciN0EuZ9XNq3lPnYtgkI5sKPXgKVaywidBN0C981SQ%3D%0Am=fr2bAoLQoVgp9h2t2fgBvfGVVX7oQ1g14g1AODFz%2FRg%3D%0As=921f4dfed39cd38f4ae7a70dfb937844d4e3faf1bc967c2f4d1f2944fa2ea31b Cheers, Thomas On 06 Jun 2014, at 23:03, Lapolla, Suzanne M (HSC) suzanne-lapo...@ouhsc.edumailto:suzanne-lapo...@ouhsc.edu wrote: Fellow Pymol Users: I may have asked this question before...but if so have forgotten. I am measuring distances between 2 atoms in 2 different objects using the distance command, and it is working perfectly, but I wonder if there is a command I can use/add so that those distances can be printed in the external gui as well as being shown in the viewer. I will be doing lots of these at the same time and the screen will get crowded. Thank you in advance. -- Robert L. Campbell, Ph.D. Senior Research Associate/Adjunct Assistant Professor Dept. of Biomedical Molecular Sciences Botterell Hall Rm 644 Queen's University, Kingston, ON K7L 3N6 Canada Tel: 613-533-6821 robert.campb...@queensu.camailto:robert.campb...@queensu.ca https://urldefense.proofpoint.com/v1/url?u=http://pldserver1.biochem.queensu.ca/~rlck=7DHVT22D9IhC0F3WohFMBA%3D%3D%0Ar=1ciN0EuZ9XNq3lPnYtgkI5sKPXgKVaywidBN0C981SQ%3D%0Am=fr2bAoLQoVgp9h2t2fgBvfGVVX7oQ1g14g1AODFz%2FRg%3D%0As=aaad7877cf1640401ae708b7b5f5a2fbe03abec4d2f0ef509e7360c0017ee225
Re: [PyMOL] command question RE printing out distances to text file
Thanks for your input Jared. I have not had a chance yet to try ANdrea's suggestions but will and will also try yours, and see what works best for me and get back to you and the forum--which has been so helpful! From: Sampson, Jared [jared.samp...@nyumc.org] Sent: Tuesday, June 17, 2014 5:54 PM To: Lapolla, Suzanne M (HSC) Cc: pymol-users@lists.sourceforge.net Subject: Re: [PyMOL] command question RE printing out distances to text file Hi Suzanne - The reason you have been getting only one distance in your output file is that your script is opening the file in “write” mode: f=open('distnew.txt','w') This will overwrite the contents of distnew.txt each time the script is run. If you want to keep all the distances without changing the rest of your script, you could open the file in “append” mode. f=open('distnew.txt',’a’) This way, each line will just get added to the bottom of the script. Keep in mind that if you want to start over with a new list of distances, you’ll need either to change the filename that gets opened (as you’ve done with “distnew.txt”) or delete the existing file. For this reason, I would go with one of the other approaches mentioned by Andreas, or look into using a list to define the atoms to which you’d like to measure the distance from the first atom, and loop through that list. Perhaps something like this (untested) bit of script would be useful, especially if you have many different atoms to check: first_atom = 'B///297/cb' second_atoms_list = ['A///17/cb', 'A///18/cb', 'A///19/cb'] with open(dist.txt, 'w') as f: for second_atom in second_atoms_list: f.write(%8.3f\n % cmd.distance(tmp, first_atom, second_atom)) Good luck! Cheers, Jared On Jun 17, 2014, at 2:21 PM, Lapolla, Suzanne M (HSC) suzanne-lapo...@ouhsc.edumailto:suzanne-lapo...@ouhsc.edu wrote: Another follow up question to this. I decided to use the measure distance python script on the pymol wiki to do this, and I was able to do it successfully with a range of residues, but my question is about the output txt file. When I run the script I get the correct distances (all 3 of them) to show on the GUI but the text file that is generated (distnew.txt) only lists one distance--so perhaps the script needs to be modified for this as well for the residues measured? The original script is at the link http://www.pymolwiki.org/index.php/Measure_Distancehttps://urldefense.proofpoint.com/v1/url?u=http://www.pymolwiki.org/index.php/Measure_Distancek=7DHVT22D9IhC0F3WohFMBA%3D%3D%0Ar=1ciN0EuZ9XNq3lPnYtgkI5sKPXgKVaywidBN0C981SQ%3D%0Am=HgvRHXkBNYGOysfvJcLojtIMeUFGMwyeOeg9H0RbBr0%3D%0As=439e1d97d8ba13b7f5cbabee32757f69dbeb6ec35476f43fd8eecc19d2e1539e and my modified version is below. Suggestions appreciated! Thank you. # This script writes the distance from # atom mol1///25/ha to atom mol1///26/ha # out to the file dist.txt # Simply change your selections to see different distances. # import PyMOL's command namespace from pymol import cmd # open dist.txt for writing f=open('distnew.txt','w') # calculate the distance and store it in dst dst=cmd.distance('tmp','B///297/cb','A///17-19/cb') # write the formatted value of the distance (dst) # to the output file f.write(%8.3f\n%dst) # close the output file. f.close() From: Robert Campbell [robert.campb...@queensu.camailto:robert.campb...@queensu.ca] Sent: Monday, June 09, 2014 10:04 AM To: pymol-users@lists.sourceforge.netmailto:pymol-users@lists.sourceforge.net Subject: Re: [PyMOL] command question RE printing out distances to text file Hi Suzanne, You can also get the distance printed in the external GUI or terminal window by using the cmd.distance version of the command. So either you can assign the distance to a variable and print it or you can print the result directly. Assuming you have two selections, sele1 and sele2 specifying the atoms of interest you can do: d = cmd.distance(sele1,sele2) print sele1,sele2,d Cheers, Rob On Mon, 2014-06-09 13:13 EDT, Thomas Holder thomas.hol...@schrodinger.commailto:thomas.hol...@schrodinger.com wrote: Hi Suzanne, you can use the get_distance command. It doesn't generate a distance object but prints the distance to the external window. https://urldefense.proofpoint.com/v1/url?u=http://pymolwiki.org/index.php/Get_Distancek=7DHVT22D9IhC0F3WohFMBA%3D%3D%0Ar=1ciN0EuZ9XNq3lPnYtgkI5sKPXgKVaywidBN0C981SQ%3D%0Am=fr2bAoLQoVgp9h2t2fgBvfGVVX7oQ1g14g1AODFz%2FRg%3D%0As=921f4dfed39cd38f4ae7a70dfb937844d4e3faf1bc967c2f4d1f2944fa2ea31b Cheers, Thomas On 06 Jun 2014, at 23:03, Lapolla, Suzanne M (HSC) suzanne-lapo...@ouhsc.edumailto:suzanne-lapo...@ouhsc.edu wrote: Fellow Pymol Users: I may have asked this question before...but if so have forgotten. I am measuring distances between 2 atoms in 2 different objects using the distance command, and it is working perfectly, but I wonder if there is a command I can use/add so that