[PyMOL] Resetting PyMOL via API for unit testing

2016-06-24 Thread Sampson, Jared M.
tl;dr: Is there a way to fully stop and restart PyMOL "sessions" using the API 
to avoid crossover between unit tests?

Hi everyone -

I'm working on unit testing for a plugin and have been trying to figure out how 
to test some functionality from within a PyMOL session.  I have a partially 
working solution, but the problem arises that I can't adequately reinitialize 
PyMOL between tests, and sometimes end up getting carryover between tests.

Here's a working example of this behavior using the built-in `unittest` testing 
framework:

```
import unittest

import __main__
__main__.pymol_argv = ['pymol','-qkc']
import pymol
from pymol import cmd

class TestPymolApi(unittest.TestCase):
def setUp(self):
pymol.finish_launching()
cmd.reinitialize()

def tearDown(self):
#cmd.quit()  # ***this line hangs if uncommented***
pass

def test_1(self):
'''No value for stored.foo.'''
from pymol import stored
with self.assertRaises(AttributeError):
stored.foo

def test_2(self):
'''Sets a value for stored.foo.'''
from pymol import stored
stored.foo = 'bar'

#def test_3(self):
#'''Fails due to carryover from test_2.'''
#self.test_1()

if __name__ == '__main__':
unittest.main()
```


Running `python basic_tests.py` yields the following output (each dot 
represents a successful test):

```
$ python basic_tests.py
..
--
Ran 2 tests in 0.043s

OK
```


But if I uncomment `test_3` and re-run (the tests are executed in standard 
string-sorting order by function name), it fails because the value of 
`stored.foo` is retained even after reinitialization after `test_2`.  (The 
`setUp` and `tearDown` functions are run before and after each test, 
respectively.)

```
$ python basic_tests.py
..F
==
FAIL: test_3 (__main__.TestPymolApi)
--
Traceback (most recent call last):
  File "basic_tests.py", line 32, in test_3
self.test_1()
  File "basic_tests.py", line 24, in test_1
stored.foo
AssertionError: AttributeError not raised

--
Ran 3 tests in 0.110s

FAILED (failures=1)
```

Maybe this is a bug in `cmd.reinitialize()`?  If not, it is unexpected behavior 
(at least in my opinion), and could be improved.

Anyway, this is why I'm trying to figure out another way to reset PyMOL using 
the API.  So if I then uncomment the `cmd.quit()` line to try to get complete 
shut down and restart of PyMOL, unittest hangs on the tearDown of the first 
test and I have to interrupt the process with .

I found an old 
thread where Jason 
mentioned using (admittedly experimental) `pymol2.PyMOL().start/stop()` to, 
well, start and stop PyMOL sessions.  However, in Open Source PyMOL 1.8.2.1, it 
appears to be broken:

```
$ python
>>> import pymol2
>>> p = pymol2.PyMOL()
>>> p.start()
Segmentation fault: 11
```

So, again, my question is: Is there any way to reliably start and stop multiple 
PyMOL sessions or completely reset it using the API?

Looking forward any suggestions or further discussion.

Cheers,
Jared








--
Attend Shape: An AT Tech Expo July 15-16. Meet us at AT Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape___
PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net

[PyMOL] Help Download structural alignment

2016-06-24 Thread Clarisa Alvarez
Hi everyone:
I am writing asking help to download the structural aligment performed in
pymol.
Thanks in advance.
Regards,
Clarisa.

2016-06-14 11:01 GMT-03:00 :

> Send PyMOL-users mailing list submissions to
> pymol-users@lists.sourceforge.net
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://lists.sourceforge.net/lists/listinfo/pymol-users
> or, via email, send a message with subject or body 'help' to
> pymol-users-requ...@lists.sourceforge.net
>
> You can reach the person managing the list at
> pymol-users-ow...@lists.sourceforge.net
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of PyMOL-users digest..."
>
>
> Today's Topics:
>
>1. Analysis of docking poses from 2 nmr-ensembles (James Starlight)
>2. Re: Analysis of docking poses from 2 nmr-ensembles
>   (Sampson, Jared M.)
>3. Selective valency on bond (McIntyre, Patrick)
>4. Re: Selective valency on bond (Andreas Warnecke)
>
>
> --
>
> Message: 1
> Date: Mon, 13 Jun 2016 15:41:58 +0200
> From: James Starlight 
> Subject: [PyMOL] Analysis of docking poses from 2 nmr-ensembles
> To: pymol-users 
> Message-ID:
> <
> caalqopzzjtykby+j_evphgvpp2_k_mhmv2holhjgf2d5pnr...@mail.gmail.com>
> Content-Type: text/plain; charset=UTF-8
>
> Dear Pymol users!
>
> I am studying protein-protein assosiation using 2 different proteins
> as test case by means of variety of computational methods.
> For my particular caseI need to compare binding poses emerged as the
> result of protein-protein docking (ensemble 1: which  consists of 20
> snapshots according to docking ranking) as well as MD simulation
> (ensemble 2: which consists of 10 snapshots each of which represents
> binding pose which has been established during long MD run).
> Loading those two ensembles in pymol as 2 different models (in
> NMR-like model format)  I need to performs some analysis  to find some
> shared trends in each of them e.g RMSD of the distances between common
> residues-pairs found in contact map analysis
> or something else. What are most trivial suggestions might be in that
> particular case?
>
>
> Thanks for the suggestions!
>
>
> James
>
>
>
> --
>
> Message: 2
> Date: Mon, 13 Jun 2016 16:08:31 +
> From: "Sampson, Jared M." 
> Subject: Re: [PyMOL] Analysis of docking poses from 2 nmr-ensembles
> To: James Starlight 
> Cc: pymol-users 
> Message-ID: 
> Content-Type: text/plain; charset="us-ascii"
>
> Hi James -
>
> First, it will be useful to split the states<
> http://www.pymolwiki.org/index.php/Split_states>.
>
> split_states ensemble1
> split_states ensemble2
> delete ensemble1
> delete ensemble2
>
> Then, superimpose all structures
> onto a reference structure for easier visualization.  This won't affect
> your distance measurements, but will make it easier to see the changes from
> one object to the next.
>
> python
> ref = 'ensemble1_0001'   # your reference object
> for obj in cmd.get_names():
> if obj != ref:
> cmd.super(obj, ref)
> python end
>
> For your residue pair analysis, you have to decide what kind of distance
> you want to measure (e.g. CA-CA; average position of all atoms in the
> residue; closest atoms, which would require looping through all atom pairs
> in each residue pair and keeping only the shortest distance).  Then create
> selection strings based on those criteria, use them in distance<
> http://pymolwiki.org/index.php/Get_Distance> measurement, and print them
> or add them to a variable to be output.  If you want to create and
> visualize distance objects, use `distance` instead of `get_distance` and
> pass a distance object name as the first parameter before the selections.
>
> python
> sel1 = "resi 100 and name CA"
> sel2 = "resi 200 and name CA"
> sel3 = "resi 300 and name CA"
> for obj in cmd.get_names():
> d12 = cmd.get_distance("{} and {}".format(obj, sel1), "{} and
> {}".format(obj, sel2))
> d23 = cmd.get_distance("{} and {}".format(obj, sel2), "{} and
> {}".format(obj, sel3))
> print "{}: '{}' to '{}' distance = {}".format(obj, sel1, sel2, d12)
> print "{}: '{}' to '{}' distance = {}".format(obj, sel2, sel3, d23)
> python end
>
> This is just a very quick example; really there are many different ways to
> do this, and you'll have to find what kind of analysis your particular
> structure needs.  Also, if you want to look at H-bonds, it will be more
> complicated, because the angle is important as well.  In this case you may
> want to look at Thomas' Polarpairs<
> http://pymolwiki.org/index.php/Polarpairs> script.
>
> Hope that