# Path: pdbtools/helper/geometry.py
# def dist(c1,c2=[0.,0.,0.]):
# def dist_sq(c1,c2=[0.,0.,0.]):
# def calcDistances(coord):
# def crossProduct(u,v):
# def dotProduct(u,v):
# def findAngle(u,v):
# def genRotMatrix(axis,theta):
# def arbRot(vector,axis,theta):
# def arbRotCoord(coord,axis,theta):
# def calcGlyCbeta(Ncoord,CAcoord,COcoord):
# def calcHXT(C_coord,O_coord,OXT_coord):
# def calcHG(CB_coord,SG_coord):
# def calcDihedrals(prevCO,currN,currCA,currCO,nextN,cutoff=6.5):
# def calcHN(prevCO,prevO,currN,currCA):
#     A = [prevCO[i] - currCA[i] for i in range(3)]
#     B = [currN[i] - currCA[i] for i in range(3)]
#     C = [currCO[i] - currCA[i] for i in range(3)]
#     D = [nextN[i] - currCA[i] for i in range(3)]
#     V1 = crossProduct(A,B)
#     V2 = crossProduct(C,B)
#     V3 = crossProduct(C,D)


import os, sys
from .helper import geometry
"""

__author__ = "Michael J. Harms"
__date__ = "070521"



def pdbNeighbors(pdb,distance_cutoff=10,sequence_cutoff=4,residue=None,
                 atom=None,calc_everything=False):
    """
    Finds number of neighbors for each residue in a pdb and returns a list of
    residues and a list of number of neighbors.
    """

    pdb = [l for l in pdb if l[0:6] == "ATOM  "]

    cb_atoms = []
    cb_coord = []
    for line_counter, line in enumerate(pdb):

        # Look for Gly CA and use to create fake CB
        if line[17:20] == "GLY" and line[13:16] == "CA ":
            cb_atoms.append("\"CB%s\"" % line[15:26])

            n = []; ca = []; co = []
            for i in range(3):
                n.append(float(pdb[line_counter-1][30+i*8:38+i*8]))
                ca.append(float(pdb[line_counter][30+i*8:38+i*8]))
                co.append(float(pdb[line_counter + 1][30+i*8:38+i*8]))
            #cb_coord.append(ca)

# Path: pdbtools/helper/geometry.py
# def dist(c1,c2=[0.,0.,0.]):
# def dist_sq(c1,c2=[0.,0.,0.]):
# def calcDistances(coord):
# def crossProduct(u,v):
# def dotProduct(u,v):
# def findAngle(u,v):
# def genRotMatrix(axis,theta):
# def arbRot(vector,axis,theta):
# def arbRotCoord(coord,axis,theta):
# def calcGlyCbeta(Ncoord,CAcoord,COcoord):
# def calcHXT(C_coord,O_coord,OXT_coord):
# def calcHG(CB_coord,SG_coord):
# def calcDihedrals(prevCO,currN,currCA,currCO,nextN,cutoff=6.5):
# def calcHN(prevCO,prevO,currN,currCA):
#     A = [prevCO[i] - currCA[i] for i in range(3)]
#     B = [currN[i] - currCA[i] for i in range(3)]
#     C = [currCO[i] - currCA[i] for i in range(3)]
#     D = [nextN[i] - currCA[i] for i in range(3)]
#     V1 = crossProduct(A,B)
#     V2 = crossProduct(C,B)
#     V3 = crossProduct(C,D)


# Path: pdbtools/neighbors.py
import os, sys
from .helper import geometry

"""

__author__ = "Michael J. Harms"
__date__ = "070521"



def pdbNeighbors(pdb,distance_cutoff=10,sequence_cutoff=4,residue=None,
                 atom=None,calc_everything=False):
    """
    Finds number of neighbors for each residue in a pdb and returns a list of
    residues and a list of number of neighbors.
    """

    pdb = [l for l in pdb if l[0:6] == "ATOM  "]

    cb_atoms = []
    cb_coord = []
    for line_counter, line in enumerate(pdb):

        # Look for Gly CA and use to create fake CB
        if line[17:20] == "GLY" and line[13:16] == "CA ":
            cb_atoms.append("\"CB%s\"" % line[15:26])

            n = []; ca = []; co = []
            for i in range(3):
                n.append(float(pdb[line_counter-1][30+i*8:38+i*8]))
                ca.append(float(pdb[line_counter][30+i*8:38+i*8]))
                co.append(float(pdb[line_counter + 1][30+i*8:38+i*8]))
            #cb_coord.append(ca)

            cb_coord.append(geometry.calcGlyCbeta(n,ca,co))