Commit 4f464856 by Francois Gygi

Add scripts to extract position,velocity,force

parent c1261b79
#!/usr/bin/python
# qbox_force.py
# extract force of an atom from Qbox output
# use: qbox_force.py atom_name file.r
import xml.sax
import sys
import math
if len(sys.argv) != 3:
print "use: ",sys.argv[0]," atom_name file.r"
sys.exit()
# Qbox output handler to extract and process <atomset>
class QboxOutputHandler(xml.sax.handler.ContentHandler):
def __init__(self):
self.readForce = 0
self.buffer = ""
def startElement(self, name, attributes):
if name == "atomset":
self.buffer = ""
elif name == "atom":
if attributes["name"] == atom_name:
self.readForce = 1
elif name == "force":
self.buffer = ""
def characters(self, data):
if self.readForce:
self.buffer += data
def endElement(self, name):
if name == "force":
if self.readForce:
force = self.buffer.split()
fx = float(force[0])
fy = float(force[1])
fz = float(force[2])
print '%.8f'%fx,'%.8f'%fy,'%.8f'%fz
self.readForce = 0
atom_name = sys.argv[1]
filename = sys.argv[2]
parser = xml.sax.make_parser()
handler = QboxOutputHandler()
parser.setContentHandler(handler)
parser.parse(sys.argv[2])
#!/usr/bin/python
# qbox_position.py
# extract position of an atom from Qbox output
# use: qbox_position.py atom_name file.r
import xml.sax
import sys
import math
if len(sys.argv) != 3:
print "use: ",sys.argv[0]," atom_name file.r"
sys.exit()
# Qbox output handler to extract and process <atomset>
class QboxOutputHandler(xml.sax.handler.ContentHandler):
def __init__(self):
self.readPos = 0
self.buffer = ""
def startElement(self, name, attributes):
if name == "atomset":
self.buffer = ""
elif name == "atom":
if attributes["name"] == atom_name:
self.readPos = 1
elif name == "position":
self.buffer = ""
def characters(self, data):
if self.readPos:
self.buffer += data
def endElement(self, name):
if name == "position":
if self.readPos:
pos = self.buffer.split()
rx = float(pos[0])
ry = float(pos[1])
rz = float(pos[2])
print '%.8f'%rx,'%.8f'%ry,'%.8f'%rz
self.readPos = 0
atom_name = sys.argv[1]
filename = sys.argv[2]
parser = xml.sax.make_parser()
handler = QboxOutputHandler()
parser.setContentHandler(handler)
parser.parse(sys.argv[2])
#!/usr/bin/python
# qbox_velocity.py
# extract velocity of an atom from Qbox output
# use: qbox_velocity.py atom_name file.r
import xml.sax
import sys
import math
if len(sys.argv) != 3:
print "use: ",sys.argv[0]," atom_name file.r"
sys.exit()
# Qbox output handler to extract and process <atomset>
class QboxOutputHandler(xml.sax.handler.ContentHandler):
def __init__(self):
self.readVelocity = 0
self.buffer = ""
def startElement(self, name, attributes):
if name == "atomset":
self.buffer = ""
elif name == "atom":
if attributes["name"] == atom_name:
self.readVelocity = 1
elif name == "velocity":
self.buffer = ""
def characters(self, data):
if self.readVelocity:
self.buffer += data
def endElement(self, name):
if name == "velocity":
if self.readVelocity:
velocity = self.buffer.split()
vx = float(velocity[0])
vy = float(velocity[1])
vz = float(velocity[2])
print '%.8f'%vx,'%.8f'%vy,'%.8f'%vz
self.readVelocity = 0
atom_name = sys.argv[1]
filename = sys.argv[2]
parser = xml.sax.make_parser()
handler = QboxOutputHandler()
parser.setContentHandler(handler)
parser.parse(sys.argv[2])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment