###############################################################################
#   zvecAdjustmentWrapperPotential.py: Wrapper to tilt the z-axis of a potential
###############################################################################
import numpy
from .WrapperPotential import parentWrapperPotential
from ..util import conversion
from ..util import _rotate_to_arbitrary_vector
class zvecAdjustmentWrapperPotential(parentWrapperPotential):
    """ Potential wrapper class that implements an adjustment to the z-axis vector of a given Potential. This can be used, for example, to tilt a disc to a desired inclination angle
    """
    def __init__(self,zvec=None,pot=None,
                 ro=None,vo=None):
        """
        NAME:

           __init__

        PURPOSE:

           initialize a zvecAdjustmentWrapper Potential

        INPUT:

           zvec - the vector along the required final z-axis

        OUTPUT:

           (none)

        HISTORY:

           2020-03-29 - Started - Mackereth (UofT)

        """
    self._setup_zvec(zvec)
    self.hasC= False
    self.hasC_dxdv= False

    def _setup_zvec(self,zvec):
        """ taken from EllipsoidalPotential """
        if not zvec is None:
            if not isinstance(zvec,numpy.ndarray):
                zvec= numpy.array(zvec)
            zvec/= numpy.sqrt(numpy.sum(zvec**2.))
            zvec_rot= _rotate_to_arbitrary_vector(\
                numpy.array([[0.,0.,1.]]),zvec,inv=True)[0]
            self._rot = zvec_rot
        else:
            self._rot = numpy.eye(3)

        return None

    def _wrap(self,attribute,*args,**kwargs):
        x,y,z= coords.cyl_to_rect(args[0],kwargs.get('phi',0.),0 if len(args) == 1 else args[1])
        xyzp= numpy.dot(self._rot,numpy.array([x,y,z]))
        R, phi, z = coords.rect_to_cyl(xyzp[0], xyzp[1], xyzp[2])
        args[0] = R
        args[1] = z
        kwargs['phi'] = phi
        return self._wrap_pot_func(attribute)(self._pot,*args,**kwargs)

@@ -377,16 +377,42 @@
 _vector%0A
+from ..util import coords%0A
 class zv
@@ -1047,24 +1047,28 @@
         %22%22%22%0A
+    
     self._se
@@ -1082,24 +1082,28 @@
 c(zvec)%0A    
+  
+  
 self.hasC= F
@@ -1107,24 +1107,28 @@
 = False%0A    
+   
+ 
 self.hasC_dx
@@ -1136,16 +1136,45 @@
 v= False
+%0A        self.isNonAxi = True
 %0A%0A    de
@@ -1694,96 +1694,261 @@
     
-x,y,z= coords.cyl_to_rect(args%5B0%5D,kwargs.get('phi',0.),0 if len(args) == 1 else args%5B1%5D)
+#need to convert input R,phi,z to x,y,z for rotation%0A        R,phi,z = args%5B0%5D,kwargs.get('phi',0.),0 if len(args) == 1 else args%5B1%5D%0A        if phi is None:%0A            phi = 0.%0A        x,y,z= coords.cyl_to_rect(R, phi, z)%0A        #apply rotation matrix
 %0A   
@@ -2000,16 +2000,41 @@
 ,y,z%5D))%0A
+        #back to R,phi,z%0A
         
@@ -2107,35 +2107,17 @@
 args
-%5B0%5D = R%0A        args%5B1%5D =
+ = (R,
  z
+)
 %0A   

include isNonAxi to ensure that phi is always needed