modifying qbox_xyz.sh to read incomplete runs

Questions and discussions regarding the use of Qbox
Forum rules
You must be a registered user to post in this forum. Registered users may also post new topics if they consider that their subject does not correspond to any topic already present on the forum.
Post Reply
gpanchap
Posts: 11
Joined: Mon May 24, 2010 1:25 am

modifying qbox_xyz.sh to read incomplete runs

Post by gpanchap »

Dear Francois,

Is there a simple way to modify your qbox_xyz.sh tool so it might also read incomplete MD output files? Currently it quits complaining about premature end of data. Thanks for your help.

Ganesh
gpanchap
Posts: 11
Joined: Mon May 24, 2010 1:25 am

Re: modifying qbox_xyz.sh to read incomplete runs

Post by gpanchap »

Ah..I got it to work. The problem was xst was looking for a style and it wasn't complete due to the crash of the MD run. Closing the different styles properly seem to work. Please ignore my question.
fgygi
Site Admin
Posts: 151
Joined: Tue Jun 17, 2008 7:03 pm

Re: modifying qbox_xyz.sh to read incomplete runs

Post by fgygi »

Dear Ganesh,

A number of these post-processing scripts do not behave well when the document is not complete (i.e. is not a well-formed XML document). Things may be improved using python scripts and progressive parsing. The following python script extracts xyz data from a run and (in the cases I tested) does not complain if the file is incomplete.

Best
Francois

Code: Select all

#!/usr/bin/python
# qbox_xyz.py
# extract positions from Qbox output
# use: qbox_xyz.py file.r > file.xyz
import xml.sax
import sys

# Qbox output handler to extract and process <atomset>
class QboxOutputHandler(xml.sax.handler.ContentHandler):
  def __init__(self):
    self.niter = 0
    self.readData = 0
    self.buffer = ""
    self.outbuf = ""

  def startElement(self, name, attributes):
    if name == "atomset":
      self.nat = 0
      self.niter += 1
      self.outbuf = ""
    elif name == "atom": 
      self.atom_name = attributes["name"]
      self.nat += 1
    elif name == "position":
      self.readData = 1 
      self.buffer = ""

  def characters(self, data):
    if self.readData:
      self.buffer += data

  def endElement(self, name):
    if name == "atomset":
      print self.nat
      print self.niter
      print self.outbuf, 
    elif name == "position":
      self.readData = 0
    elif name == "atom":
      self.pos = self.buffer.split()
      self.outbuf += self.atom_name+" "
      self.outbuf += str(float(self.pos[0])*0.529177)+" "
      self.outbuf += str(float(self.pos[1])*0.529177)+" "
      self.outbuf += str(float(self.pos[2])*0.529177)+" "
      self.outbuf += "\n"

parser = xml.sax.make_parser()
handler = QboxOutputHandler()
parser.setContentHandler(handler)

file = open(sys.argv[1])
s = file.read(8192)
while s !="": 
  parser.feed(s)
  s = file.read(8192)

parser.reset()
#print "parsing done"
Post Reply