Change X Coordinate Of A Pdb File
2
0
Entering edit mode
10.5 years ago
Kanika ▴ 10

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 • 3.2k views
ADD COMMENT
0
Entering edit mode

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

ADD REPLY
2
Entering edit mode
10.5 years ago
Neilfws 49k

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 COMMENT
0
Entering edit mode

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 REPLY
0
Entering edit mode

All true, answer amended accordingly.

ADD REPLY
0
Entering edit mode
10.5 years ago

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="http://www.w3.org/1999/XSL/Transform" "="" rel="nofollow">http://www.w3.org/1999/XSL/Transform'
        xmlns:PDBx="http://pdbml.pdb.org/schema/pdbx-v32.xsd"
        version='1.0'
        >
<xsl:output method="xml"/>

<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>

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

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

</xsl:stylesheet>

Usage :

xsltproc stylesheet.xsl pdb.xml
ADD COMMENT

Login before adding your answer.

Traffic: 1759 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6