# Path: openpathsampling/engines/toy/snapshot.py
# class ToySnapshot(BaseSnapshot):
#     """
#     Simulation snapshot. Only references to coordinates and velocities
#     """
# 
#     @property
#     def topology(self):
#         return self.engine.topology
# 
#     @property
#     def masses(self):
#         return self.topology.masses


from .test_helpers import assert_items_equal
from openpathsampling.engines.toy import ToySnapshot
from openpathsampling.engines.external_engine import *
from openpathsampling.engines.snapshot import SnapshotDescriptor
import openpathsampling as paths
import openpathsampling.engines as peng
import numpy as np
import pytest
import psutil
import os
import glob
import linecache
import logging
engine_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                          "external_engine")


class ExampleExternalEngine(peng.ExternalEngine):
    """Trivial external engine for engine.c in the tests.
    """
    SnaphotClass = ToySnapshot
    InternalizedSnapshotClass = ToySnapshot

    def read_frame_from_file(self, filename, frame_num):
        # under most circumstances, start with linecache.checkcache and
        # setting the value of the first line
        linecache.checkcache(filename)
        first_line = frame_num + 1

        # create a snapshot out of lines starting with first_line... if
        # nothing exists, linecache returns '', so we return None.
        # Otherwise, try to make a snapshot and return "partial" if we fail
        line = linecache.getline(filename, first_line)
        if line == '':
            snap = None
        else:
            try:
                splitted = line.split()
                if len(splitted) == 2:
                    coords = float(splitted[0])
                    vels = float(splitted[1])
                else:
                    raise ValueError()  # force the raise we then ignore

# Path: openpathsampling/engines/toy/snapshot.py
# class ToySnapshot(BaseSnapshot):
#     """
#     Simulation snapshot. Only references to coordinates and velocities
#     """
# 
#     @property
#     def topology(self):
#         return self.engine.topology
# 
#     @property
#     def masses(self):
#         return self.topology.masses


# Path: openpathsampling/tests/test_external_engine.py
from .test_helpers import assert_items_equal
from openpathsampling.engines.toy import ToySnapshot
from openpathsampling.engines.external_engine import *
from openpathsampling.engines.snapshot import SnapshotDescriptor
import openpathsampling as paths
import openpathsampling.engines as peng
import numpy as np
import pytest
import psutil
import os
import glob
import linecache
import logging

engine_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                          "external_engine")


class ExampleExternalEngine(peng.ExternalEngine):
    """Trivial external engine for engine.c in the tests.
    """
    SnaphotClass = ToySnapshot
    InternalizedSnapshotClass = ToySnapshot

    def read_frame_from_file(self, filename, frame_num):
        # under most circumstances, start with linecache.checkcache and
        # setting the value of the first line
        linecache.checkcache(filename)
        first_line = frame_num + 1

        # create a snapshot out of lines starting with first_line... if
        # nothing exists, linecache returns '', so we return None.
        # Otherwise, try to make a snapshot and return "partial" if we fail
        line = linecache.getline(filename, first_line)
        if line == '':
            snap = None
        else:
            try:
                splitted = line.split()
                if len(splitted) == 2:
                    coords = float(splitted[0])
                    vels = float(splitted[1])
                else:
                    raise ValueError()  # force the raise we then ignore

                snap = ToySnapshot(coordinates=np.array([[coords]]),