From: Diego Gomes (diego.enry_at_gmail.com)
Date: Fri May 03 2024 - 10:38:56 CDT

Hi Ryan,
I'd keep it simple with Axel's solution.

If you want to keep things in VMD here is a commented example of how to
load chains in a certain order then write in a different one.
I'm using a previously downloaded structure "3WTG-assembly1.cif". Make sure
to adapt to your case.

# Load new molecule (saving it's molid as "old")
set old [ mol new 3WTG-assembly1.cif ]

# Get the list of chains
set chains [ lsort -unique [ [ atomselect $old all ] get chain ] ]

# Reverse that list (Replace "my_chains" with your favorite order)
set my_chains [ lreverse $chains ]

# Count the total number of atoms
set natoms [ molinfo $old get numatoms ]

# Create a temporary molecule and fill it with dummy atoms
set tmp [ mol new atoms $natoms ]

# Initialize the dummy atoms pool
set sel [atomselect $tmp "all"]
animate dup $tmp
mol rename $tmp "reordered"

# List of things to copy
set copy_list { name type radius resname resid chain x y z occupancy
element segname }

# counter for atom indexes
set first 0

# Loop over chains
foreach chain $my_chains {
    # Select atoms for a given chain.
    set oldmol [ atomselect $old "chain $chain" ]

    # Save its number of atoms.
    set last [ expr $first + [ $oldmol num ] - 1 ]

    # Select a portion of the new molecule.
    set newmol [ atomselect $tmp "index $first to $last" ]

    # Copy data from old molecule to new one.
    $newmol set $copy_list [ $oldmol get $copy_list ]

    # Update counter
    set first $last
}

# Write the reordered PDB file
animate write pdb reordered.pdb $tmp

Friendly,
Diego.

On Thu, May 2, 2024 at 11:07 PM Axel Kohlmeyer <akohlmey_at_gmail.com> wrote:
>
> I would create selections for each chain separately and write out a PDB
file for each and then manually merge those files in the desired order with
a text editor or a similar tool.
>
> On Thu, May 2, 2024 at 11:16 PM Ryan Woltz <rlwoltz_at_ucdavis.edu> wrote:
>>
>> Dear all,
>>
>> I hope I can explain this problem correctly but the solution is to
save the atoms of a PDB in a new order. For example my protein is loaded
chain A then chain C then chain B and I would like to save chain A then
chain B then chain C. I'm sure I could do this with python or bash but I'm
doing a lot of changes to the protein while it is loaded and would like to
not do another script in case it breaks everything.
>>
>> Here is my problem overall. I have a series of models from
alphafold with multiple chains (A B C D). This is in the C4 symmetry
(cyclic). I'm trying to analyze the structures and compare them all but
because AF has random chain assignments or is inconsistent the order going
clockwise might be A -> D -> C -> B. in this scenario I need to switch
chains B and D. I have built a script to do distance measurement to figure
out the relative order (ADCB) and which the chain names of D and B. The
problem is when I save the pdb the atom numbers for the pdb is still out of
order and when I'm trying to load the models as a trajectory it loads the
first structure then every model after line by line. This means in the
trajectory chain B is still labeled as chain D because it starts at line
3000 of the pdb. This is assuming that chains A gor from 1-1000 chain B
should go from lines 1000-2000 so on and so forth. When I pull up each pdb
individually the naming is correct so this ordering problem is just for
loading the pdbs as a trajectory.
>>
>> in short how can I make sure chain B is always saved after chain A,
chain C is after chain D and chain D is last in the pdb if they were not
loaded in this order? I tried selections in various order to save for
example:
>>
>> animate write pdb test.pdb sel [atomselect 0 "chain A B C D"]
>>
>> vs
>>
>> animate write pdb test.pdb sel [atomselect 0 "chain D B C A"]
>>
>> but it always saves the chains in the order it was loaded.
>>
>> should I just reorder the pdb with a python script or something outside
vmd?
>>
>> Thank you and sorry for a confusing explanation of the problem.
>>
>> Ryan
>>
>
>
> --
> Dr. Axel Kohlmeyer akohlmey_at_gmail.com https://urldefense.com/v3/__https://goo.gl/1wk0__;!!DZ3fjg!5eu4bg52fp-c99EQ2oLD3-az5bmzqzqMJ7juf03B_q4wMnCOMcWshXx_2df8xV1ELLzM0LugvzSTTFevY-ja$
> Institute for Computational Molecular Science and HPC, https://urldefense.com/v3/__https://icmshpc.com__;!!DZ3fjg!5eu4bg52fp-c99EQ2oLD3-az5bmzqzqMJ7juf03B_q4wMnCOMcWshXx_2df8xV1ELLzM0LugvzSTTHhFHvsO$
> College of Science & Technology, Temple University, Philadelphia PA, USA

--
Diego Enry B. Gomes, PhD
Department of Physics at Auburn University &
NIH Center for Macromolecular Modeling and Visualization
Leach Science Center - Ste. 3182 - Auburn, AL
dgomes_at_auburn.edu