Hi Istvan,

I can reproduce the same issue. Seems to be some unintended behavior with
how this multistate pseudoatom object is created. I've attached a modified
center_of_mass.py script so that it should behave the way you expect. Let
me know if this works for you.

Example that I tried with this:

fetch 1nmr
run center_of_mass_states_joined.py
com 1nmr, object=COM
wizard distance
# created distances between traj atom and pseudoatom

Hope that helps,
Jarrett J.

On Tue, Jul 18, 2023 at 12:52 PM Istvan Kolossvary <ikolos...@gmail.com>
wrote:

> Hi,
>
> I have a simulation trajectory loaded in Pymol and I want to display
> certain interatomic distances interactively. This works perfectly fine with
> normal atoms, I can see how these selected distances change over the course
> of the simulation using the wizard and playing the movie. However, it seems
> that this feature doesn't work with pseudo atoms. I defined a couple of
> center-of-mass pseudo atoms using this script
> http://www.pymolwiki.org/index.php/center_of_mass. The script creates
> separate objects corresponding to the different COMs and each COM object
> has the same number of states as the trajectory object. I can use the
> wizard, select the distances, which show on the display, but when I play
> the movie, the distance values are not updated while the pseudo atoms do
> move around. The first thing I figured was that maybe the COM objects
> should be merged in a single object. So, I did that but to no avail, the
> distances are not updated while I play the movie. I must be overlooking
> something, can you tell me why this is not working?
>
> Thank you very much,
>
>    Istvan
> _______________________________________________
> PyMOL-users mailing list
> Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net
> Unsubscribe:
> https://sourceforge.net/projects/pymol/lists/pymol-users/unsubscribe



-- 

*Jarrett Johnson* | Senior Developer, PyMOL
'''
See more here: http://www.pymolwiki.org/index.php/center_of_mass

DESCRIPTION

   Places a pseudoatom at the center of mass

   Author: Sean Law
   Michigan State University
   slaw (at) msu . edu

SEE ALSO

   pseudoatom, get_com
'''

from __future__ import print_function
from pymol import cmd


def com(selection, state=None, mass=None, object=None, quiet=1, **kwargs):
    quiet = int(quiet)
    if (object == None):
        try:
            object = cmd.get_legal_name(selection)
            object = cmd.get_unused_name(object + "_COM", 0)
        except AttributeError:
            object = 'COM'
    cmd.delete(object)

    if (state != None):
        x, y, z = get_com(selection, mass=mass, quiet=quiet)
        if not quiet:
            print("%f %f %f" % (x, y, z))
        cmd.pseudoatom(object, pos=[x, y, z], **kwargs)
        cmd.show("spheres", object)
    else:
        for i in range(cmd.count_states()):
            x, y, z = get_com(selection, mass=mass, state=i + 1, quiet=quiet)
            if not quiet:
                print("State %d:%f %f %f" % (i + 1, x, y, z))
                obj_name = f"_COM{object}{i}"
                cmd.pseudoatom(obj_name, pos=[x, y, z], **kwargs)
            cmd.show("spheres", 'last ' + obj_name)
        cmd.join_states(object, f"_COM{object}*")
        cmd.delete(f"_COM{object}*")

cmd.extend("com", com)


def get_com(selection, state=1, mass=None, quiet=1):
    """
 DESCRIPTION

    Calculates the center of mass

    Author: Sean Law
    Michigan State University
    slaw (at) msu . edu
    """
    quiet = int(quiet)

    totmass = 0.0
    if mass != None and not quiet:
        print("Calculating mass-weighted COM")

    state = int(state)
    model = cmd.get_model(selection, state)
    x, y, z = 0, 0, 0
    for a in model.atom:
        if (mass != None):
            m = a.get_mass()
            x += a.coord[0] * m
            y += a.coord[1] * m
            z += a.coord[2] * m
            totmass += m
        else:
            x += a.coord[0]
            y += a.coord[1]
            z += a.coord[2]

    if (mass != None):
        return x / totmass, y / totmass, z / totmass
    else:
        return x / len(model.atom), y / len(model.atom), z / len(model.atom)

cmd.extend("get_com", get_com)

# vi:expandtab:sw=3
_______________________________________________
PyMOL-users mailing list
Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net
Unsubscribe: 
https://sourceforge.net/projects/pymol/lists/pymol-users/unsubscribe

Reply via email to