Question: Change X Coordinate Of A Pdb File
gravatar for Kanika
7.8 years ago by
Kanika10 wrote:

I am new to perl and this may seem a vague question. I have a PDB file and I just want to add 10 to all X coordinates of the file. can anyone please help me with the code??

pdb perl coordinates • 2.4k views
ADD COMMENTlink modified 5.6 years ago by Biostar ♦♦ 20 • written 7.8 years ago by Kanika10

Basically, what you're asking is how to access the coordinate section of a PDB file. Lots of answers to this question:

ADD REPLYlink written 7.8 years ago by Neilfws48k
gravatar for Neilfws
7.8 years ago by
Sydney, Australia
Neilfws48k wrote:

Without writing the code for you, here's an outline of what your code needs to do:

  1. Open PDB file for reading
  2. Read each line consecutively
  3. If line DOES NOT begin with "ATOM" or "HETATM", print it
  4. If line DOES begin with ATOM or HETATM:
  5. extract the number in the column that corresponds to X coordinate
  6. add 10 to it
  7. print out line, substituting new X value
  8. Close PDB file

So the main Perl concepts that you need to learn are:

  • how to open, close and read a file; then print lines from it
  • how to match regular expressions to a line
  • how to split space-delimited lines into arrays
  • basic arithmetic on variables ("add 10 to x")

A lot of this is covered by answers to a previous question. But really, it's probably better to use an existing parser which will have considered the difficult cases (see Bosco's comment).

ADD COMMENTlink modified 7.8 years ago • written 7.8 years ago by Neilfws48k

alas, space-delimited arrays fails with PDB files, several gotchas: - there's a column for insertions, alternate conformations - chain id's can sometimes be a space or a letter/number - there are no defined spaces between the x,y,z coordinates. there are accidental spaces if not all significant figures are used

to parse pdb, you must read specific positions on the line.

ADD REPLYlink written 7.8 years ago by Bosco Ho90

All true, answer amended accordingly.

ADD REPLYlink written 7.8 years ago by Neilfws48k
gravatar for Pierre Lindenbaum
7.8 years ago by
France/Nantes/Institut du Thorax - INSERM UMR1087
Pierre Lindenbaum116k wrote:

if you're using a XML-PDB file, you can use the following xslt stylesheet to add 10 to all the elements Cartn_x:

<xsl:stylesheet xmlns:xsl="&lt;a href="" "="" rel="nofollow">'
<xsl:output method="xml"/>

<xsl:template match="/">

<xsl:template match="PDBx:Cartn_x">
<xsl:value-of select="10 + number(.)"/>

<xsl:template match="*|@*|text()">
<xsl:apply-templates select="@*|*|text()"/>


Usage :

xsltproc stylesheet.xsl pdb.xml
ADD COMMENTlink written 7.8 years ago by Pierre Lindenbaum116k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1822 users visited in the last hour