# Path: acpype/params.py
# MAXTIME = 3 * 3600
# TLEAP_TEMPLATE = """
# verbosity 1
# source %(leapAmberFile)s
# source %(leapGaffFile)s
# mods = loadamberparams %(acBase)s.frcmod
# %(res)s = loadmol2 %(acMol2FileName)s
# check %(res)s
# saveamberparm %(res)s %(acBase)s.prmtop %(acBase)s.inpcrd
# saveoff %(res)s %(acBase)s.lib
# quit
# """


import math
import os
import subprocess as sub
import sys
    import warnings
    import openbabel as obl
from shutil import which
from acpype.params import Pi

def dotproduct(aa, bb):
    """scalar product"""
    return sum((a * b) for a, b in zip(aa, bb))


def cross_product(a, b):
    """cross product"""
    c = [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]]
    return c


def length(v):
    """distance between 2 vectors"""
    return math.sqrt(dotproduct(v, v))


def vec_sub(aa, bb):
    """vector A - B"""
    return [a - b for a, b in zip(aa, bb)]


def imprDihAngle(a, b, c, d):
    """calculate improper dihedral angle"""
    ba = vec_sub(a, b)
    bc = vec_sub(c, b)
    cb = vec_sub(b, c)
    cd = vec_sub(d, c)
    n1 = cross_product(ba, bc)
    n2 = cross_product(cb, cd)

# Path: acpype/params.py
# MAXTIME = 3 * 3600
# TLEAP_TEMPLATE = """
# verbosity 1
# source %(leapAmberFile)s
# source %(leapGaffFile)s
# mods = loadamberparams %(acBase)s.frcmod
# %(res)s = loadmol2 %(acMol2FileName)s
# check %(res)s
# saveamberparm %(res)s %(acBase)s.prmtop %(acBase)s.inpcrd
# saveoff %(res)s %(acBase)s.lib
# quit
# """


# Path: acpype/utils.py
import math
import os
import subprocess as sub
import sys
    import warnings
    import openbabel as obl
from shutil import which
from acpype.params import Pi


def dotproduct(aa, bb):
    """scalar product"""
    return sum((a * b) for a, b in zip(aa, bb))


def cross_product(a, b):
    """cross product"""
    c = [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]]
    return c


def length(v):
    """distance between 2 vectors"""
    return math.sqrt(dotproduct(v, v))


def vec_sub(aa, bb):
    """vector A - B"""
    return [a - b for a, b in zip(aa, bb)]


def imprDihAngle(a, b, c, d):
    """calculate improper dihedral angle"""
    ba = vec_sub(a, b)
    bc = vec_sub(c, b)
    cb = vec_sub(b, c)
    cd = vec_sub(d, c)
    n1 = cross_product(ba, bc)
    n2 = cross_product(cb, cd)

    angle = math.acos(dotproduct(n1, n2) / (length(n1) * length(n2))) * 180 / Pi