# Path: openpathsampling/integration_tools.py
# def error_if_no(name, package_name, has_package):
# def _chain_import(*packages):
# def error_if_no_simtk_unit(name):
# def error_if_no_mdtraj(name):
# def error_if_to_openmm(name):
#     HAS_SIMTK_UNIT = False
#     HAS_SIMTK_UNIT = True
#     HAS_MDTRAJ = False
#     HAS_MDTRAJ = True
#     HAS_OPENMM = False
#     HAS_OPENMM = True


import numpy as np
import pandas as pd
import logging
from openpathsampling.netcdfplus import StorableNamedObject
from openpathsampling.integration_tools import error_if_no_mdtraj, md
        except Exception:
            # we try a fix and add multiples of 10000 to the resSeq

            logger.info('Normal reconstruction of topology failed. '
                        'Trying a fix to the 10k residue ID problem.')

            for ci in np.unique(atoms['chainID']):
                chain_atoms = atoms[atoms['chainID'] == ci]
                indices = chain_atoms.index.tolist()

                old_residue_id = 0
                multiplier = 0
                places = []
                for row, res_id in zip(indices, list(chain_atoms['resSeq'])):
                    if res_id < old_residue_id:
                        if multiplier > 0:
                            atoms.loc[places, 'resSeq'] += 10000 * multiplier

                        places = []
                        multiplier += 1

                    if multiplier > 0:
                        places.append(row)

                    old_residue_id = res_id

                if multiplier > 0:
                    atoms.loc[places, 'resSeq'] += 10000 * multiplier

            # this function is really slow! Reads ~ 1000 atoms per second

# Path: openpathsampling/integration_tools.py
# def error_if_no(name, package_name, has_package):
# def _chain_import(*packages):
# def error_if_no_simtk_unit(name):
# def error_if_no_mdtraj(name):
# def error_if_to_openmm(name):
#     HAS_SIMTK_UNIT = False
#     HAS_SIMTK_UNIT = True
#     HAS_MDTRAJ = False
#     HAS_MDTRAJ = True
#     HAS_OPENMM = False
#     HAS_OPENMM = True


# Path: openpathsampling/engines/topology.py
import numpy as np
import pandas as pd
import logging
from openpathsampling.netcdfplus import StorableNamedObject
from openpathsampling.integration_tools import error_if_no_mdtraj, md

        except Exception:
            # we try a fix and add multiples of 10000 to the resSeq

            logger.info('Normal reconstruction of topology failed. '
                        'Trying a fix to the 10k residue ID problem.')

            for ci in np.unique(atoms['chainID']):
                chain_atoms = atoms[atoms['chainID'] == ci]
                indices = chain_atoms.index.tolist()

                old_residue_id = 0
                multiplier = 0
                places = []
                for row, res_id in zip(indices, list(chain_atoms['resSeq'])):
                    if res_id < old_residue_id:
                        if multiplier > 0:
                            atoms.loc[places, 'resSeq'] += 10000 * multiplier

                        places = []
                        multiplier += 1

                    if multiplier > 0:
                        places.append(row)

                    old_residue_id = res_id

                if multiplier > 0:
                    atoms.loc[places, 'resSeq'] += 10000 * multiplier

            # this function is really slow! Reads ~ 1000 atoms per second

            md_topology = md.Topology.from_dataframe(atoms, bonds)