# 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/data/polar.py
# PARAM_FILE = os.path.join(os.path.split(__file__)[0],"polar_param.txt")
# POLAR_CHARGE_DICT, POLAR_RADII_DICT = _readParam(PARAM_FILE)
# def _readParam(param_file):


import os, sys
from .helper import geometry
from .data.polar import POLAR_CHARGE_DICT
from math import pi
    Actually do moment calculation on centered coordinates.
    """

    # unit conversion
    elementary_q = 1.602176487e-19 # elementary charge in C
    debye_conv = 3.33564e-30       # 1 Debye in C*m
    k = elementary_q*1e-10/debye_conv

    num_atoms = len(charges)

    # Calculate the moment by sum(q(i)*r(i)) for x, y, and z
    moment = [sum([coord[j][i]*charges[j] for j in range(num_atoms)])
            for i in range(3)]

    moment = [m*k for m in moment]

    return moment


def pdbMoment(pdb):
    """
    Calculate the dipole moment of a pdb file using the charge set in
    pdb_data.polar.
    """

    # Parse pdb file
    pdb = [l for l in pdb if l[0:4] == "ATOM"]

    # Grab fractional charge of each atom and coordinates from pdb file
    try:

# 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/data/polar.py
# PARAM_FILE = os.path.join(os.path.split(__file__)[0],"polar_param.txt")
# POLAR_CHARGE_DICT, POLAR_RADII_DICT = _readParam(PARAM_FILE)
# def _readParam(param_file):


# Path: pdbtools/moment.py
import os, sys
from .helper import geometry
from .data.polar import POLAR_CHARGE_DICT
from math import pi

    Actually do moment calculation on centered coordinates.
    """

    # unit conversion
    elementary_q = 1.602176487e-19 # elementary charge in C
    debye_conv = 3.33564e-30       # 1 Debye in C*m
    k = elementary_q*1e-10/debye_conv

    num_atoms = len(charges)

    # Calculate the moment by sum(q(i)*r(i)) for x, y, and z
    moment = [sum([coord[j][i]*charges[j] for j in range(num_atoms)])
            for i in range(3)]

    moment = [m*k for m in moment]

    return moment


def pdbMoment(pdb):
    """
    Calculate the dipole moment of a pdb file using the charge set in
    pdb_data.polar.
    """

    # Parse pdb file
    pdb = [l for l in pdb if l[0:4] == "ATOM"]

    # Grab fractional charge of each atom and coordinates from pdb file
    try:

        charges = [POLAR_CHARGE_DICT[l[17:21]][l[12:16]] for l in pdb]