# Path: PyContact/core/Scripting.py
# class PyContactJob:
#     """Job class that is given a JobConfig and input files and handles
#     running/analyzing the job as such."""
#     def __init__(self, topo, traj, name, configuration):
#         self.topo = topo
#         self.traj = traj
#         self.name = name
#         self.configuration = configuration
#         self.analyzer = None
# 
#     def runJob(self, ncores=1):
#         """Runs contact analysis and accumulation with ncores threads."""
#         print("Running job: " + self.name + " on " + str(ncores) + " cores.")
#         self.analyzer = Analyzer(self.topo,self.traj, self.configuration.cutoff, self.configuration.hbondcutoff, self.configuration.hbondcutangle, self.configuration.sel1, self.configuration.sel2)
#         self.analyzer.runFrameScan(ncores)
#         self.analyzer.runContactAnalysis(self.configuration.map1, self.configuration.map2, ncores)
# 
#     def writeSessionToFile(self, fname=""):
#         """Writes the current analysis session to a file with either self.name + .session or fname as output filename"""
#         if fname != "":
#             DataHandler.writeSessionToFile(fname, self.analyzer)
#         else:
#             DataHandler.writeSessionToFile(self.name + ".session", self.analyzer)
#         print("Wrote session to file")
# 
# class JobConfig:
#     """Configuration/Settings for a PyContact contact analysis job"""
#     def __init__(self, cutoff, hbondcutoff, hbondcutangle, map1, map2, sel1, sel2):
#         self.cutoff = cutoff
#         self.hbondcutoff = hbondcutoff
#         self.hbondcutangle = hbondcutangle
#         self.map1 = map1
#         self.map2 = map2
#         self.sel1 = sel1
#         self.sel2 = sel2
# 
# Path: PyContact/core/Biochemistry.py
# class AccumulationMapIndex:
#     """Enum and mapping for atom properties.
#        Used to dynamically define keys and have a bijective nomenclature for all properties
#     """
#     index, name, resid, resname, segid = range(5)
#     mapping = ["i.", "nm.", "r.", "rn.", "s."]
#     vmdsel = ["index", "name", "resid", "resname", "segname"]


import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import matplotlib
from PyContact.core.Scripting import PyContactJob, JobConfig
from PyContact.core.Biochemistry import AccumulationMapIndex
"""
A simple example of an animated plot
"""
matplotlib.use("qt5agg")


jobAllMD = PyContactJob("./PyContact/exampleData/rpn11_ubq_interface-ionized.psf",
                   "./PyContact/exampleData/short.dcd", "md_all", JobConfig(5.0, 2.5, 120, [0,0,0,1,1,0], [0,0,0,1,1,0], "segid UBQ", "segid RN11"))

jobAllMD.runJob(1)
contacts = jobAllMD.analyzer.finalAccumulatedContacts

map1 = [0,0,0,1,1,0]
map2 = [0,0,0,1,1,0]
label1 = "UBQ"
label2 = "RN11"
attribute = "test"
threshold = 0.0
nsPerFrame = 1.0

minmaxresids1 = []
minmaxresids2 = []

for cont in contacts:

# Path: PyContact/core/Scripting.py
# class PyContactJob:
#     """Job class that is given a JobConfig and input files and handles
#     running/analyzing the job as such."""
#     def __init__(self, topo, traj, name, configuration):
#         self.topo = topo
#         self.traj = traj
#         self.name = name
#         self.configuration = configuration
#         self.analyzer = None
# 
#     def runJob(self, ncores=1):
#         """Runs contact analysis and accumulation with ncores threads."""
#         print("Running job: " + self.name + " on " + str(ncores) + " cores.")
#         self.analyzer = Analyzer(self.topo,self.traj, self.configuration.cutoff, self.configuration.hbondcutoff, self.configuration.hbondcutangle, self.configuration.sel1, self.configuration.sel2)
#         self.analyzer.runFrameScan(ncores)
#         self.analyzer.runContactAnalysis(self.configuration.map1, self.configuration.map2, ncores)
# 
#     def writeSessionToFile(self, fname=""):
#         """Writes the current analysis session to a file with either self.name + .session or fname as output filename"""
#         if fname != "":
#             DataHandler.writeSessionToFile(fname, self.analyzer)
#         else:
#             DataHandler.writeSessionToFile(self.name + ".session", self.analyzer)
#         print("Wrote session to file")
# 
# class JobConfig:
#     """Configuration/Settings for a PyContact contact analysis job"""
#     def __init__(self, cutoff, hbondcutoff, hbondcutangle, map1, map2, sel1, sel2):
#         self.cutoff = cutoff
#         self.hbondcutoff = hbondcutoff
#         self.hbondcutangle = hbondcutangle
#         self.map1 = map1
#         self.map2 = map2
#         self.sel1 = sel1
#         self.sel2 = sel2
# 
# Path: PyContact/core/Biochemistry.py
# class AccumulationMapIndex:
#     """Enum and mapping for atom properties.
#        Used to dynamically define keys and have a bijective nomenclature for all properties
#     """
#     index, name, resid, resname, segid = range(5)
#     mapping = ["i.", "nm.", "r.", "rn.", "s."]
#     vmdsel = ["index", "name", "resid", "resname", "segname"]


# Path: tests/map_animate.py
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import matplotlib
from PyContact.core.Scripting import PyContactJob, JobConfig
from PyContact.core.Biochemistry import AccumulationMapIndex

"""
A simple example of an animated plot
"""
matplotlib.use("qt5agg")


jobAllMD = PyContactJob("./PyContact/exampleData/rpn11_ubq_interface-ionized.psf",
                   "./PyContact/exampleData/short.dcd", "md_all", JobConfig(5.0, 2.5, 120, [0,0,0,1,1,0], [0,0,0,1,1,0], "segid UBQ", "segid RN11"))

jobAllMD.runJob(1)
contacts = jobAllMD.analyzer.finalAccumulatedContacts

map1 = [0,0,0,1,1,0]
map2 = [0,0,0,1,1,0]
label1 = "UBQ"
label2 = "RN11"
attribute = "test"
threshold = 0.0
nsPerFrame = 1.0

minmaxresids1 = []
minmaxresids2 = []

for cont in contacts:

    minmaxresids1.append(int(cont.key1[AccumulationMapIndex.resid]))