#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2017 Malcolm Ramsay <malramsay64@gmail.com>
#
# Distributed under terms of the MIT license.

"""Run an analysis on a trajectory."""

import click
import gsd.hoomd
import numpy as np

from ..sdrun import options
from .order import orientational_order


@click.command()
@options.arg_infile
@options.arg_outfile
def order(infile, outfile):
    """Compute the orientational order for each frame of a trajectory."""
    trajectory = gsd.hoomd.open(infile, 'rb')
    with open(outfile, 'w') as dst:
        print('Timestep, OrientOrder', file=dst)
        for snapshot in trajectory:
            order = orientational_order(snapshot)
            print(f'{snapshot.configuration.step}, {np.sum(order > 0.9) / len(order)}',
                  file=dst)

@@ -206,16 +206,32 @@
 ry.%22%22%22%0A%0A
+import logging%0A%0A
 import c
@@ -235,16 +235,16 @@
 t click%0A
-
 import g
@@ -340,16 +340,85 @@
 _order%0A%0A
+logger = logging.getLogger(__name__)%0Alogger.setLevel(logging.DEBUG)%0A%0A
 %0A@click.
@@ -713,16 +713,82 @@
     for 
+index in range(len(trajectory)):%0A            try:%0A                
 snapshot
@@ -788,18 +788,17 @@
 napshot 
-in
+=
  traject
@@ -800,17 +800,152 @@
 ajectory
-:
+%5Bindex%5D%0A            except RuntimeError:%0A                logger.info(f'Frame %7Bindex%7D corrupted, continuing...')%0A                continue
 %0A       

Add error handling for corrupted trajectory frames