Chain attribute

38 views
Skip to first unread message

Theresa

unread,
Oct 6, 2017, 12:26:50 PM10/6/17
to MDnalysis discussion
Hi all,

(Hopefully) easy question here. I would like to modify the chain of a selection before writing it to a pdb file, but I can't seem to find how to adjust the chain name. I'm using v16, if it matters.

My procedure:

u = mda.Universe(mypdb.pdb)
myatoms = u.select_atoms('segid SEG')

myatoms.chains = 'A'

myatoms.writepdb('newpdb.pdb')


However, there doesn't appear to be a chain or chains attribute. I know MDAnalysis has this information, as when I write the PDB file, there is a chain listed. How do I access this information to change it?

Thank you very much,
Theresa

Richard Gowers

unread,
Oct 6, 2017, 2:22:59 PM10/6/17
to MDnalysis discussion
Hi Theresa

MDAnalysis treats the chains in a PDB file as segments, so the chains will be referred to as segments.

If you just want to rename the chain, you could do:

myatoms = u.select_atoms('segid SEG')
myatoms.segments.segids = 'NEW'
myatoms.write('new.pdb')

If you want to split a chain into two, there's an extra step of creating a new Segment within the Universe:

myatoms = u.select_atoms('segid SEG')
newseg = u.add_Segment(segid='NEW')
myatoms.segments = newseg
myatoms.write('new.pdb')

Hope that helps, let us know otherwise!
Richard

Richard Gowers

unread,
Oct 6, 2017, 2:24:21 PM10/6/17
to MDnalysis discussion
Oops, just realised there's a small mistake there, to assign to the new segment it's:

myatoms.residues.segments = newseg

Theresa

unread,
Oct 10, 2017, 9:12:13 AM10/10/17
to MDnalysis discussion
Hi  Richard,

Thank you very much! That helps.

Theresa
Reply all
Reply to author
Forward
0 new messages