<jupyter_start><jupyter_text>Some testing and analysis of the new `Snapshot` implementation<jupyter_code>from __future__ import print_function

import numpy as np
import openpathsampling as paths
import openpathsampling.engines.features as features<jupyter_output><empty_output><jupyter_text>Function to show the generated source code<jupyter_code>from IPython.display import Markdown

def code_to_md(snapshot_class):
    md = '```py\n'
    for f, s in snapshot_class.__features__.debug.items():
        if s is not None:
            md += s
        else:
            md += 'def ' + f + '(...):\n    # user defined\n    pass' 
        md += '\n\n'
    md += '```'

    return md<jupyter_output><empty_output><jupyter_text>Check generated source code Generate simple Snapshot without any features using factory<jupyter_code>EmptySnap = paths.engines.snapshot.SnapshotFactory('no', [], 'Empty', use_lazy_reversed=False)<jupyter_output><empty_output><jupyter_text>Generate Snapshot with overridden `.copy` method.<jupyter_code>@features.base.attach_features([
    features.velocities,
    features.coordinates,
    features.box_vectors,
    features.topology
])
class A(paths.BaseSnapshot):
    def copy(self):
        return 'copy'<jupyter_output><empty_output><jupyter_text>Check that subclassing with overridden copy needs more overriding.<jupyter_code>#! lazy
# lazy because of some issue with Py3k comparing strings
try:
    @features.base.attach_features([
    ])
    class B(A):
        pass
except RuntimeWarning as e:
    print(e)
else:
    raise RuntimeError('Should have raised a RUNTIME warning')    
a = A()
assert(a.copy() == 'copy')
#! ignore
Markdown(code_to_md(A))
#! ignore
Markdown(code_to_md(EmptySnap))
SuperSnap = paths.engines.snapshot.SnapshotFactory(
    'my', [
        paths.engines.features.coordinates,
        paths.engines.features.box_vectors,
        paths.engines.features.velocities
    ], 'No desc', use_lazy_reversed=False)
#! ignore
Markdown(code_to_md(SuperSnap))
MegaSnap = paths.engines.snapshot.SnapshotFactory(
    'mega', [
        paths.engines.features.statics,
        paths.engines.features.kinetics,
        paths.engines.features.engine
    ], 'Long desc', use_lazy_reversed=False)
#! ignore
Markdown(code_to_md(MegaSnap))<jupyter_output><empty_output><jupyter_text>Test subclassing<jupyter_code>@features.base.attach_features([
])
class HyperSnap(MegaSnap):
    pass<jupyter_output><empty_output><jupyter_text>Test subclassing with redundant features (should work / be ignored)<jupyter_code>@features.base.attach_features([
    paths.engines.features.statics,
])
class HyperSnap(MegaSnap):
    pass<jupyter_output><empty_output><jupyter_text>Test subclassing with conflicting features (should not work)<jupyter_code>try:
    @features.base.attach_features([
        paths.engines.features.statics,
        paths.engines.features.coordinates
    ])
    class HyperSnap(MegaSnap):
        pass
except RuntimeWarning as e:
    print(e)
else:
    raise RuntimeError('Should have raised a RUNTIME warning')    
#! ignore
Markdown(code_to_md(paths.engines.openmm.MDSnapshot))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10867492850333652, 'fraction_numerical': 0.00031776294884016526, 'mean_word_length': 4.581560283687943, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '650202', 'license': 'MIT', 'n_tokens_mistral': 1047, 'n_tokens_neox': 1024, 'n_words': 201, 'path': 'examples/tests/test_snapshot.ipynb', 'repo_name': 'apdealbao/openpathsampling', 'size': '3147'}