This repository has been archived by the owner on Jul 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(issue #64) Changes to the python script and the .cfg file are done. …
…As soon as testing is done I'll merge with master.
- Loading branch information
kozlac
committed
Jan 13, 2016
1 parent
250d16c
commit af2c9fe
Showing
3 changed files
with
165 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#!/usr/bin/env python | ||
|
||
""" | ||
Check intermediate computed energies form an APBS run | ||
""" | ||
|
||
import sys, re | ||
from apbs_logger import Logger | ||
|
||
error_tolerance = 1e-6 | ||
|
||
class ElecEnergy: | ||
""" | ||
extracts and compares computed intermediate energies | ||
""" | ||
|
||
pattern = r'\s(?P<label>[a-zA-Z]+ [a-zA-Z]+ = )[\-]?(?P<x>[0-9]+(\.[0-9]+)?(E[\+,\-][0-9]+)?)' | ||
|
||
def __init__(self, label, x): | ||
""" | ||
creates an elecEnergy from supplies values | ||
""" | ||
self.label = label | ||
self.x = x | ||
|
||
def __init__(self, line): | ||
""" | ||
extract energy results from a file at a given line | ||
""" | ||
m = re.search(self.pattern, line) | ||
self.label = m.group('label') | ||
self.x = float(m.group('x')) | ||
|
||
def __repr__(self): | ||
return "ElecEnergy{ label:%S, x:%g" % (self.label, self.x) | ||
|
||
def diff(self, other): | ||
""" | ||
compares the value of two energy calculations | ||
""" | ||
|
||
return abs( getattr(self, d) - getattr(other, d) ) | ||
|
||
def short(self): | ||
return self.label | ||
|
||
|
||
def extract_energy(energy_class, lines, start_pattern, ): | ||
""" | ||
extracts intermediate energies | ||
""" | ||
energy_list = [] | ||
|
||
for line_number, line_text in enumerate(lines): | ||
|
||
if line_text.lstrip().startswith(start_pattern): | ||
if re.search(energy_class.pattern, line_text): | ||
energy_list.append(parse_energy(energy_class, line_text)) | ||
|
||
|
||
return energy_list | ||
|
||
|
||
def parse_energy( energy_class, lines): | ||
|
||
energy_item = energy_class(lines) | ||
|
||
return energy_item.x | ||
|
||
|
||
def check_energies(input_file): | ||
|
||
print "Checking for intermidiate energies in input file %s" % input_file | ||
|
||
f = None | ||
try: | ||
f = open(input_file, 'r') | ||
except IOError: | ||
print >> sys.stderr, "Couldn't read from energy file %s" % input_file | ||
|
||
input_lines = f.readlines() | ||
|
||
energy_list = extract_energy(ElecEnergy, input_lines, 'Total electrostatic energy') | ||
energy_list += extract_energy(ElecEnergy, input_lines, 'Mobile charge energy') | ||
energy_list += extract_energy(ElecEnergy, input_lines, 'Fixed charge energy') | ||
energy_list += extract_energy(ElecEnergy, input_lines, 'Dielectric energy') | ||
|
||
return energy_list | ||
|
||
def test(): | ||
|
||
l = open('energy.log', 'w') | ||
logger = Logger(sys.stderr, l) | ||
energy_list = check_energies('actio_stdout.txt') | ||
print energy_list | ||
|
||
|
||
if __name__ == '__main__': | ||
print >> sys.stderr, "The python source files %s is a module and not runnable" % sys.argv[0] | ||
sys.exit(1) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters