From: Josh Vermaas (
Date: Fri May 03 2024 - 11:12:21 CDT

Or topotools. You'd want the selections to mol command.

set selA [atomselect 0 "chain A"]
set selB [atomselect 0 "chain B"]
set selC [atomselect 0 "chain C"]
set selD [atomselect 0 "chain D"]
#Do some magic to make a list with the selections in the right order
based on your distance criteria
set sellist [somelogicgoeshere]
#Make a new molecule that does respect the order.
set newmol [::TopoTools::selections2mol $sellist]
#Write out to a file
animate write psf newmol.psf $newmol
animate write pdb newmol.pdb $newmol


On 5/2/24 11:30 PM, Axel Kohlmeyer 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 <> 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;!!DZ3fjg!9ewE89ZYEP7X-T-VCmwCsfQbtrERB4sdx294psSsByMexFAoUS2VPLQNnvLM3QMjl5v3IZwPVb29abyn2TU$
> <;!!DZ3fjg!510gqLteXC5mIraDob7boyCRUFw7UVRa2SI1-8FvjrDfj_TR8tnkS46CZm202qFyLRnSwzB90gb98dlHXg$>
> Institute for Computational Molecular Science and HPC,
> <;!!DZ3fjg!510gqLteXC5mIraDob7boyCRUFw7UVRa2SI1-8FvjrDfj_TR8tnkS46CZm202qFyLRnSwzB90gYoNBR6wg$>
> College of Science & Technology, Temple University, Philadelphia PA, USA

Josh Vermaas
Assistant Professor, Plant Research Laboratory and Biochemistry and Molecular Biology
Michigan State University