Using xml_grep

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
fgygi
Site Admin
Posts: 167
Joined: Tue Jun 17, 2008 7:03 pm

Using xml_grep

Post by fgygi »

Extracting xml elements from Qbox output is made easier using the xml_grep command. xml_grep is part of the Perl Twig package.

On midway.rcc.uchicago.edu, e.g., you can use module load perl to access the command. A few examples:

Extracting the <etotal> element from the output file gs3.r:

Code: Select all

$ xml_grep etotal gs3.r
<?xml version="1.0" ?>
<xml_grep version="0.9" date="Sat Oct 12 12:17:25 2019">
<file filename="gs3.r">
  <etotal>   -2626.17326085 </etotal>
</file>
</xml_grep>
Extract the <etotal> element with only the text content:

Code: Select all

$ xml_grep --text_only etotal gs3.r 
   -2626.17326085 
Using XPath syntax to extract just atom "O2_110":

Code: Select all

$ xml_grep 'atom[@name="O2_110"]' gs3.r 
<?xml version="1.0" ?>
<xml_grep version="0.9" date="Sat Oct 12 12:23:34 2019">
<file filename="gs3.r">
  <atom name="O2_110" species="oxygen">
    <position> 4.67035000 13.06390000 -3.37325000 </position>
    <velocity> 0.00000000 0.00000000 0.00000000 </velocity>
    <force> 0.00785222 0.00282495 0.00500539 </force>
  </atom>
</file>
</xml_grep>
Extract the position of atom "O2_110", text only:

Code: Select all

 
$ xml_grep --text_only 'atom[@name="O2_110"]/position' gs3.r 
 4.67035000 13.06390000 -3.37325000 
Post Reply