<commit_before>##############################################################################
# MDTraj: A Python Library for Loading, Saving, and Manipulating
#         Molecular Dynamics Trajectories.
# Copyright 2012-2014 Stanford University and the Authors
#
# Authors: <NAME>
# Contributors: <NAME>, <NAME>, <NAME>, <NAME>, <NAME>
#
# MDTraj is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 2.1
# of the License, or (at your option) any later version.
#
# This library 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with MDTraj. If not, see <http://www.gnu.org/licenses/>.
##############################################################################


##############################################################################
# Imports
##############################################################################

from __future__ import print_function, division
import os
import warnings
from copy import deepcopy
from collections import Iterable
import numpy as np
import functools

from mdtraj.formats import DCDTrajectoryFile
from mdtraj.formats import BINPOSTrajectoryFile
from mdtraj.formats import XTCTrajectoryFile
from mdtraj.formats import TRRTrajectoryFile
from mdtraj.formats import HDF5TrajectoryFile
from mdtraj.formats import NetCDFTrajectoryFile
from mdtraj.formats import LH5TrajectoryFile
from mdtraj.formats import PDBTrajectoryFile
from mdtraj.formats import MDCRDTrajectoryFile
from mdtraj.formats import DTRTrajectoryFile
from mdtraj.formats import LAMMPSTrajectoryFile
from mdtraj.formats import XYZTrajectoryFile
from mdtraj.formats import GroTrajectoryFile
from mdtraj.formats import TNGTrajectoryFile
from mdtraj.formats import AmberNetCDFRestartFile
from mdtraj.formats import AmberRestartFile

from mdtraj.formats.prmtop import load_prmtop
from mdtraj.formats.psf import load_psf
from mdtraj.formats.mol2 import load_mol2
from mdtraj.formats.gro import load_gro
from mdtraj.formats.arc import load_arc
from mdtraj.formats.hoomdxml import load_hoomdxml
from mdtraj.core.topology import Topology
from mdtraj.core.residue_names import _SOLVENT_TYPES
from mdtraj.utils import (ensure_type, in_units_of, lengths_and_angles_to_box_vectors,
                          box_vectors_to_lengths_and_angles, cast_indices,
                          deprecated)
from mdtraj.utils.six.moves import xrange
from mdtraj.utils.six import PY3, string_types
from mdtraj import _rmsd
from mdtraj import FormatRegistry
from mdtraj.geometry import distance
from mdtraj.geometry import _geometry

##############################################################################
# Globals
##############################################################################

__all__ = ['open', 'load', 'iterload', 'load_frame', 'load_topology', 'join',
           'Trajectory']
# supported extensions for constructing topologies
_TOPOLOGY_EXTS = ['.pdb', '.pdb.gz', '.h5','.lh5', '.prmtop', '.parm7',
                  '.psf', '.mol2', '.hoomdxml', '.gro', '.arc', '.hdf5']


##############################################################################
# Utilities
##############################################################################


def _assert_files_exist(filenames):
    """Throw an IO error if files don't exist

    Parameters
    ----------
    filenames : {str, [str]}
        String or list of strings to check
    """
    if isinstance(filenames, string_types):
        filenames = [filenames]
    for fn in filenames:
        if not (os.path.exists(fn) and os.path.isfile(fn)):
            raise IOError('No such file: %s' % fn)


def _assert_files_or_dirs_exist(names):
    """Throw an IO error if files don't exist

    Parameters
    ----------
    filenames : {str, [str]}
        String or list of strings to check
    """
    if isinstance(names, string_types):
        names = [names]
    for fn in names:
        if not (os.path.exists(fn) and \
                        (os.path.isfile(fn) or os.path.isdir(fn))):
            raise IOError('No such file: %s' % fn)

if PY3:
    def _hash_numpy_array(x):
        hash_value = hash(x.shape)
        hash_value ^= hash(x.strides)
        hash_value ^= hash(x.data.tobytes())
        return hash_value
else:
    def _hash_numpy_array(x):
        writeable = x.flags.writeable
        try:
            x.flags.writeable = False
            hash_value = hash(x.shape)
            hash_value ^= hash(x.strides)
            hash_value ^= hash(x.data)
        finally:
            x.flags.writeable = writeable
        return hash_value


def load_topology(filename, **kwargs):
    """Load a topology

    Parameters
    ----------
    filename : str
        Path to a file containing a system topology. The following extensions
        are supported: '.pdb', '.pdb.gz', '.h5','.lh5', '.prmtop', '.parm7',
            '.psf', '.mol2', '.hoomdxml'

    Returns
    -------
    topology : md.Topology
    """
    return _parse_topology(filename, **kwargs)


def _parse_topology(top, **kwargs):
    """Get the topology from a argument of indeterminate type
    If top is a string, we try loading a pdb, if its a trajectory
    we extract its topology.

    Returns
    -------
    topology : md.Topology
    """

    if isinstance(top, string_types):
        ext = _get_extension(top)
    else:
        ext = None  # might not be a string

    if isinstance(top, string_types) and (ext in ['.pdb', '.pdb.gz', '.h5','.lh5']):
        _traj = load_frame(top, 0, **kwargs)
        topology = _traj.topology
    elif isinstance(top, string_types) and (ext in ['.prmtop', '.parm7']):
        topology = load_prmtop(top, **kwargs)
    elif isinstance(top, string_types) and (ext in ['.psf']):
        topology = load_psf(top, **kwargs)
    elif isinstance(top, string_types) and (ext in ['.mol2']):
        topology = load_mol2(top, **kwargs).topology
    elif isinstance(top, string_types) and (ext in ['.gro']):<commit_msg>Added support for prm7 topology file extension.<commit_after>##############################################################################
# MDTraj: A Python Library for Loading, Saving, and Manipulating
#         Molecular Dynamics Trajectories.
# Copyright 2012-2014 Stanford University and the Authors
#
# Authors: <NAME>
# Contributors: <NAME>, <NAME>, <NAME>, <NAME>, <NAME>
#
# MDTraj is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 2.1
# of the License, or (at your option) any later version.
#
# This library 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with MDTraj. If not, see <http://www.gnu.org/licenses/>.
##############################################################################


##############################################################################
# Imports
##############################################################################

from __future__ import print_function, division
import os
import warnings
from copy import deepcopy
from collections import Iterable
import numpy as np
import functools

from mdtraj.formats import DCDTrajectoryFile
from mdtraj.formats import BINPOSTrajectoryFile
from mdtraj.formats import XTCTrajectoryFile
from mdtraj.formats import TRRTrajectoryFile
from mdtraj.formats import HDF5TrajectoryFile
from mdtraj.formats import NetCDFTrajectoryFile
from mdtraj.formats import LH5TrajectoryFile
from mdtraj.formats import PDBTrajectoryFile
from mdtraj.formats import MDCRDTrajectoryFile
from mdtraj.formats import DTRTrajectoryFile
from mdtraj.formats import LAMMPSTrajectoryFile
from mdtraj.formats import XYZTrajectoryFile
from mdtraj.formats import GroTrajectoryFile
from mdtraj.formats import TNGTrajectoryFile
from mdtraj.formats import AmberNetCDFRestartFile
from mdtraj.formats import AmberRestartFile

from mdtraj.formats.prmtop import load_prmtop
from mdtraj.formats.psf import load_psf
from mdtraj.formats.mol2 import load_mol2
from mdtraj.formats.gro import load_gro
from mdtraj.formats.arc import load_arc
from mdtraj.formats.hoomdxml import load_hoomdxml
from mdtraj.core.topology import Topology
from mdtraj.core.residue_names import _SOLVENT_TYPES
from mdtraj.utils import (ensure_type, in_units_of, lengths_and_angles_to_box_vectors,
                          box_vectors_to_lengths_and_angles, cast_indices,
                          deprecated)
from mdtraj.utils.six.moves import xrange
from mdtraj.utils.six import PY3, string_types
from mdtraj import _rmsd
from mdtraj import FormatRegistry
from mdtraj.geometry import distance
from mdtraj.geometry import _geometry

##############################################################################
# Globals
##############################################################################

__all__ = ['open', 'load', 'iterload', 'load_frame', 'load_topology', 'join',
           'Trajectory']
# supported extensions for constructing topologies
_TOPOLOGY_EXTS = ['.pdb', '.pdb.gz', '.h5','.lh5', '.prmtop', '.parm7', '.prm7',
                  '.psf', '.mol2', '.hoomdxml', '.gro', '.arc', '.hdf5']


##############################################################################
# Utilities
##############################################################################


def _assert_files_exist(filenames):
    """Throw an IO error if files don't exist

    Parameters
    ----------
    filenames : {str, [str]}
        String or list of strings to check
    """
    if isinstance(filenames, string_types):
        filenames = [filenames]
    for fn in filenames:
        if not (os.path.exists(fn) and os.path.isfile(fn)):
            raise IOError('No such file: %s' % fn)


def _assert_files_or_dirs_exist(names):
    """Throw an IO error if files don't exist

    Parameters
    ----------
    filenames : {str, [str]}
        String or list of strings to check
    """
    if isinstance(names, string_types):
        names = [names]
    for fn in names:
        if not (os.path.exists(fn) and \
                        (os.path.isfile(fn) or os.path.isdir(fn))):
            raise IOError('No such file: %s' % fn)

if PY3:
    def _hash_numpy_array(x):
        hash_value = hash(x.shape)
        hash_value ^= hash(x.strides)
        hash_value ^= hash(x.data.tobytes())
        return hash_value
else:
    def _hash_numpy_array(x):
        writeable = x.flags.writeable
        try:
            x.flags.writeable = False
            hash_value = hash(x.shape)
            hash_value ^= hash(x.strides)
            hash_value ^= hash(x.data)
        finally:
            x.flags.writeable = writeable
        return hash_value


def load_topology(filename, **kwargs):
    """Load a topology

    Parameters
    ----------
    filename : str
        Path to a file containing a system topology. The following extensions
        are supported: '.pdb', '.pdb.gz', '.h5','.lh5', '.prmtop', '.parm7',
            '.prm7', '.psf', '.mol2', '.hoomdxml'

    Returns
    -------
    topology : md.Topology
    """
    return _parse_topology(filename, **kwargs)


def _parse_topology(top, **kwargs):
    """Get the topology from a argument of indeterminate type
    If top is a string, we try loading a pdb, if its a trajectory
    we extract its topology.

    Returns
    -------
    topology : md.Topology
    """

    if isinstance(top, string_types):
        ext = _get_extension(top)
    else:
        ext = None  # might not be a string

    if isinstance(top, string_types) and (ext in ['.pdb', '.pdb.gz', '.h5','.lh5']):
        _traj = load_frame(top, 0, **kwargs)
        topology = _traj.topology
    elif isinstance(top, string_types) and (ext in ['.prmtop', '.parm7', '.prm7']):
        topology = load_prmtop(top, **kwargs)
    elif isinstance(top, string_types) and (ext in ['.psf']):
        topology = load_psf(top, **kwargs)
    elif isinstance(top, string_types) and (ext in ['.mol2']):
        topology = load_mol2(top, **kwargs).topology
    elif isinstance(top, string_types) and (ext in ['.gro']):
{'fraction_non_alphanumeric': 0.18906533933791578, 'fraction_numerical': 0.0052145058070632855, 'mean_word_length': 3.616338439095551, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 8}, '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}}
{'dir': 'git-commits-cleaned', 'id': '631121', 'n_tokens_mistral': 3809, 'n_tokens_neox': 3655, 'n_words': 1126}