__author__ = 'christopher'
from pyiid.sim.dynamics import classical_dynamics
from copy import deepcopy as dc
import numpy as np
from ase.atoms import Atoms

from pyiid.wrappers.elasticscatter import ElasticScatter
from pyiid.calc.pdfcalc import PDFCalc

def test_dynamics():

    ideal_atoms = Atoms('Au4', [[0, 0, 0], [3, 0, 0], [0, 3, 0], [3, 3, 0]])
    ideal_atoms.set_velocities(np.zeros((len(ideal_atoms), 3)))
    s = ElasticScatter()
    gobs = s.get_pdf(ideal_atoms)

    ideal_atoms.positions *= 1.02

    calc = PDFCalc(obs_data=gobs, scatter=s, conv=1, potential='rw')
    ideal_atoms.set_calculator(calc)

    e = .5

    traj = classical_dynamics(ideal_atoms, e, 10)

    pe_list = []
    for atoms in traj:
        pe_list.append(atoms.get_potential_energy())
    min_pe = np.min(pe_list)
    assert min_pe < .1

def test_reverse_dynamics():

    ideal_atoms = Atoms('Au4', [[0, 0, 0], [3, 0, 0], [0, 3, 0], [3, 3, 0]])
    ideal_atoms.set_velocities(np.zeros((len(ideal_atoms), 3)))
    s = ElasticScatter()
    s.set_processor('CPU', 'flat')
    gobs = s.get_pdf(ideal_atoms)

    ideal_atoms.positions *= 1.02

    calc = PDFCalc(obs_data=gobs, scatter=s, conv=1, potential='rw')
    ideal_atoms.set_calculator(calc)

    e = -.5

    traj = classical_dynamics(ideal_atoms, e, 10)

    pe_list = []
    for atoms in traj:
        pe_list.append(atoms.get_potential_energy())
    min_pe = np.min(pe_list)
    assert min_pe < .1

if __name__ == '__main__':
    import nose
    nose.runmodule(argv=['-s', '--with-doctest'], exit=False)
@@ -245,16 +245,49 @@
  PDFCalc
+%0A# from ase.visualize import view
 %0A%0Adef te
@@ -653,18 +653,18 @@
     e = 
+1
 .
-5
 %0A%0A    tr
@@ -695,34 +695,33 @@
 ideal_atoms, e, 
-10
+5
 )%0A%0A    pe_list =
@@ -1052,16 +1052,18 @@
 er()%0A   
+ #
  s.set_p
@@ -1276,10 +1276,10 @@
  = -
+1
 .
-5
 %0A%0A  
@@ -1326,10 +1326,9 @@
  e, 
-10
+5
 )%0A%0A 
@@ -1440,32 +1440,49 @@
 np.min(pe_list)%0A
+    # view(traj)%0A
     assert min_p

fix dynamics tests to be shorter/travis ready