Finally solved!
runCommand("coordset #0 " + line.strip().split()[0] + “; wait 1”) did the trick.


Thank you so much, Merry Christmas and Happy New Year
Lorena


El 23 dic 2020, a las 19:31, Eric Pettersen <pett@cgl.ucsf.edu> escribió:

Hi Lorena,
I don't think a per-frame script is really the approach you want.  What you want to do is open your trajectory, use "coordset" commands to go to the representative frames, and then write them out.  Here's a possible script (that you would run simply be opening it with the "open" command [make sure the file name ends in '.py']):

from chimera import runCommand
with open("/HDD/lroldan/Master/Metals_bA/Template/2LFM/MD/GaMD/clusters_frame.txt", "r") as f:
    cluster_number = 1
    for line in f:
        if line.startswith('#'): #comment line
            continue
        runCommand("coordset #0 " + line.strip().split()[0])
        name = "/HDD/lroldan/Master/Metals_bA/Template/2LFM/MD/GaMD/Clusters/_" + str(cluster_number)
        runCommand("write format pdb 0 " + name)
        cluster_number += 1

--Eric

Eric Pettersen
UCSF Computer Graphics Lab


On Dec 23, 2020, at 8:20 AM, Lorena Roldán <Lorena.Roldan@uab.cat> wrote:

Good afternoon,

I contact you as I would really appreciate your help. I have a MD trajectory which I have processed into Clusters with the Analysis ... Cluster tool. I have saved the resulting file with the members and the representative frame, but now I would like to save those representative frames in separate PDB files. This process is extremely tedious if manually done, so I have tried to perform a script:


with open("/HDD/lroldan/Master/Metals_bA/Template/2LFM/MD/GaMD/clusters_frame.txt", "r") as f:
    lines=f.readlines()
    cluster_number = 1
    for i in range(len(lines)):
        frame = i
        if mdInfo["frame number"] == frame:
            name = "/HDD/lroldan/Master/Metals_bA/Template/2LFM/MD/GaMD/Clusters/_" + str(cluster_number)
            runCommand('write format pdb 0 $name)


which would be run in the "Per-frame Commands", in order to 1) encounter the frames of the cluster and 2) save each frame in a PDB file, correctly numbered.


However, this script is not working, and I would greatly thank any help you could provide me with.


Lorena.

--
Lorena Roldán Martín
PhD Student in Bioinformatics

Departament de Química
Unitat de Química Física

Campus de la UAB · 08193 Bellaterra
(Cerdanyola del Vallès) · Barcelona · Spain

+34 690799431
www.uab.cat



_______________________________________________
Chimera-users mailing list: Chimera-users@cgl.ucsf.edu
Manage subscription: https://plato.cgl.ucsf.edu/mailman/listinfo/chimera-users