# 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/ContactFilters.py
# class ScoreFilter(BinaryFilter):
#     """Compares contact score of every frame, only adds contact if true for all frames."""
#     def __init__(self, name, operator, value, ftype):
#         super(ScoreFilter, self).__init__(name, operator, value)
#         self.ftype = ftype
# 
#     def filterContacts(self, contacts):
#         filtered = []
#         op = Operator()
#         if self.ftype == u"Mean":
#             for c in contacts:
#                 mean = c.mean_score()
#                 if op.compare(mean, self.value, self.operator):
#                     filtered.append(c)
#         elif self.ftype == u"Median":
#             for c in contacts:
#                 med = c.median_score()
#                 if op.compare(med, self.value, self.operator):
#                     filtered.append(c)
#         elif self.ftype == u"HB %":
#             for c in contacts:
#                 med = c.hbond_percentage()
#                 print(med)
#                 if op.compare(med, self.value, self.operator):
#                     filtered.append(c)
#         return filtered


from PyContact.core.Scripting import (PyContactJob, JobConfig)
from PyContact.core.ContactFilters import ScoreFilter
from numpy import linalg as LA
from sklearn.decomposition import PCA
from sklearn.manifold import TSNE
import numpy as np
import matplotlib.pyplot as plt

jobAllMD = PyContactJob("./PyContact/exampleData/rpn11_ubq_interface-ionized.psf","./PyContact/exampleData/short.dcd", "test", 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)
# jobAllMD.writeSessionToFile()
contacts = jobAllMD.analyzer.finalAccumulatedContacts


# 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/ContactFilters.py
# class ScoreFilter(BinaryFilter):
#     """Compares contact score of every frame, only adds contact if true for all frames."""
#     def __init__(self, name, operator, value, ftype):
#         super(ScoreFilter, self).__init__(name, operator, value)
#         self.ftype = ftype
# 
#     def filterContacts(self, contacts):
#         filtered = []
#         op = Operator()
#         if self.ftype == u"Mean":
#             for c in contacts:
#                 mean = c.mean_score()
#                 if op.compare(mean, self.value, self.operator):
#                     filtered.append(c)
#         elif self.ftype == u"Median":
#             for c in contacts:
#                 med = c.median_score()
#                 if op.compare(med, self.value, self.operator):
#                     filtered.append(c)
#         elif self.ftype == u"HB %":
#             for c in contacts:
#                 med = c.hbond_percentage()
#                 print(med)
#                 if op.compare(med, self.value, self.operator):
#                     filtered.append(c)
#         return filtered


# Path: testing/pca.py
from PyContact.core.Scripting import (PyContactJob, JobConfig)
from PyContact.core.ContactFilters import ScoreFilter
from numpy import linalg as LA
from sklearn.decomposition import PCA
from sklearn.manifold import TSNE
import numpy as np
import matplotlib.pyplot as plt


jobAllMD = PyContactJob("./PyContact/exampleData/rpn11_ubq_interface-ionized.psf","./PyContact/exampleData/short.dcd", "test", 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)
# jobAllMD.writeSessionToFile()
contacts = jobAllMD.analyzer.finalAccumulatedContacts


filter = ScoreFilter("score", "greater", 0.0, u"Median")