--- /dev/null
+# Copyright (C) 2010 W. Trevor King <wking@drexel.edu>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# The author may be contacted at <wking@drexel.edu> on the Internet, or
+# write to Trevor King, Drudge's University, Physics Dept., 3141 Chestnut St.,
+# Philadelphia PA 19104, USA.
+
+
+"""`sawsim` output parsing utilities.
+
+* `Event` instances represent domain state transitions.
+* `parse()` parses the output of a typical `sawsim` run.
+"""
+
+
+from collections import namedtuple
+
+
+
+Event = namedtuple(
+ typename='Event',
+ field_names=['force', 'intial_state', 'final_state'])
+
+
+def parse(text):
+ """Parse the output of a `sawsim` run.
+
+ >>> text = '''#Force (N)\\tinitial state\\tFinal state
+ ... 2.90301e-10\\tfolded\\tunfolded
+ ... 2.83948e-10\\tfolded\\tunfolded
+ ... 2.83674e-10\\tfolded\\tunfolded
+ ... 2.48384e-10\\tfolded\\tunfolded
+ ... 2.43033e-10\\tfolded\\tunfolded
+ ... 2.77589e-10\\tfolded\\tunfolded
+ ... 2.85343e-10\\tfolded\\tunfolded
+ ... 2.67796e-10\\tfolded\\tunfolded
+ ... '''
+ >>> events = list(parse(text))
+ >>> len(events)
+ 8
+ >>> events[0] # doctest: +ELLIPSIS
+ Event(force=2.9030...e-10, intial_state='folded', final_state='unfolded')
+ """
+ for line in text.splitlines():
+ line = line.strip()
+ if len(line) == 0 or line.startswith('#'):
+ continue
+ fields = line.split('\t')
+ if len(fields) != 3:
+ raise ValueError(fields)
+ force,initial_state,final_state = fields
+ yield Event(float(force), initial_state, final_state)