From 392816a807dfe1c8494f0517254b94c469a9ed0c Mon Sep 17 00:00:00 2001
From: julient31 <julien.tranchida1@gmail.com>
Date: Tue, 24 Apr 2018 16:36:30 -0600
Subject: [PATCH] Commit JT 042418

- adding the README
- some corrects pair_spin*.cpp/h
---
 .../exchange_fcc_cobalt.dat                   |  5 +++
 .../exchange_fit_fcc_co/exchange_fit.py       | 32 +++++++++++++++++++
 .../exchange_bcc_iron.dat                     |  2 ++
 .../exchange_fit_fcc_ni/exchange_fcc_ni.dat   | 10 +++---
 .../exchange_fit_fcc_ni/exchange_fcc_ni2.dat  |  5 +++
 .../exchange_fit_fcc_ni/exchange_fit.py       |  5 +--
 src/SPIN/README                               | 25 +++++++++++++++
 src/SPIN/atom_vec_spin.h                      | 10 ------
 src/SPIN/compute_spin.h                       | 10 ------
 src/SPIN/fix_langevin_spin.h                  | 10 ------
 src/SPIN/fix_nve_spin.cpp                     | 14 +++++++-
 src/SPIN/fix_nve_spin.h                       | 10 ------
 src/SPIN/fix_precession_spin.h                | 10 ------
 src/SPIN/pair_spin.h                          |  4 +++
 src/SPIN/pair_spin_dmi.cpp                    | 25 ++++++++-------
 src/SPIN/pair_spin_dmi.h                      | 10 ------
 src/SPIN/pair_spin_exchange.h                 | 10 ------
 src/SPIN/pair_spin_me.h                       | 10 ------
 src/SPIN/pair_spin_neel.h                     | 10 ------
 19 files changed, 107 insertions(+), 110 deletions(-)
 create mode 100644 examples/SPIN/cobalt_fcc/exchange_fit_fcc_co/exchange_fcc_cobalt.dat
 create mode 100644 examples/SPIN/cobalt_fcc/exchange_fit_fcc_co/exchange_fit.py
 create mode 100644 examples/SPIN/nickel/exchange_fit_fcc_ni/exchange_fcc_ni2.dat
 create mode 100644 src/SPIN/README

diff --git a/examples/SPIN/cobalt_fcc/exchange_fit_fcc_co/exchange_fcc_cobalt.dat b/examples/SPIN/cobalt_fcc/exchange_fit_fcc_co/exchange_fcc_cobalt.dat
new file mode 100644
index 0000000000..dce45c090d
--- /dev/null
+++ b/examples/SPIN/cobalt_fcc/exchange_fit_fcc_co/exchange_fcc_cobalt.dat
@@ -0,0 +1,5 @@
+2.503 0.01476
+3.54  0.001497
+4.33  0.001578
+5.01  -0.001224
+5.597 0.000354
diff --git a/examples/SPIN/cobalt_fcc/exchange_fit_fcc_co/exchange_fit.py b/examples/SPIN/cobalt_fcc/exchange_fit_fcc_co/exchange_fit.py
new file mode 100644
index 0000000000..09be6db3e4
--- /dev/null
+++ b/examples/SPIN/cobalt_fcc/exchange_fit_fcc_co/exchange_fit.py
@@ -0,0 +1,32 @@
+#Program fitting the exchange interaction
+#Model curve: Bethe-Slater function
+import numpy as np, pylab, tkinter
+import matplotlib.pyplot as plt
+from scipy.optimize import curve_fit
+from decimal import *
+
+print("Loop begin")
+
+#Definition of the Bethe-Slater function
+def func(x,a,b,c):
+    return 4*a*((x/c)**2)*(1-b*(x/c)**2)*np.exp(-(x/c)**2)
+
+#Exchange coeff table (data to fit)
+rdata, Jdata = np.loadtxt('exchange_fcc_cobalt.dat', usecols=(0,1), unpack=True)
+plt.plot(rdata, Jdata, 'b-', label='data')
+
+#Perform the fit
+popt, pcov = curve_fit(func, rdata, Jdata, bounds=(0, [500.,5.,5.]))
+plt.plot(rdata, func(rdata, *popt), 'r--', label='fit')
+
+#Print the fitted params
+print("Parameters: a={:.10} (in meV), b={:.10} (adim), c={:.10} (in Ang)".format(*popt))
+
+#Ploting the result
+plt.xlabel('r_ij')
+pylab.xlim([0,6.5])
+plt.ylabel('J_ij')
+plt.legend()
+plt.show()
+
+print("Loop end")
diff --git a/examples/SPIN/iron/exchange_fit_bcc_iron/exchange_bcc_iron.dat b/examples/SPIN/iron/exchange_fit_bcc_iron/exchange_bcc_iron.dat
index 7cfe1cb586..58134f2444 100644
--- a/examples/SPIN/iron/exchange_fit_bcc_iron/exchange_bcc_iron.dat
+++ b/examples/SPIN/iron/exchange_fit_bcc_iron/exchange_bcc_iron.dat
@@ -1,3 +1,5 @@
 2.4824 0.01948336
 2.8665 0.01109
 4.0538 -0.0002176
+4.753 -0.001714
+4.965 -0.001986
diff --git a/examples/SPIN/nickel/exchange_fit_fcc_ni/exchange_fcc_ni.dat b/examples/SPIN/nickel/exchange_fit_fcc_ni/exchange_fcc_ni.dat
index 4e5aa47659..376f6fd162 100644
--- a/examples/SPIN/nickel/exchange_fit_fcc_ni/exchange_fcc_ni.dat
+++ b/examples/SPIN/nickel/exchange_fit_fcc_ni/exchange_fcc_ni.dat
@@ -1,5 +1,5 @@
-2.495 8.3
-3.524 -3.99
-4.31 0.998
-4.99 -0.955
-5.56 0.213
+2.492 0.0028027
+3.524 0.0000816
+4.316 0.0003537
+4.984 0.0001632
+5.572 0.0000408
diff --git a/examples/SPIN/nickel/exchange_fit_fcc_ni/exchange_fcc_ni2.dat b/examples/SPIN/nickel/exchange_fit_fcc_ni/exchange_fcc_ni2.dat
new file mode 100644
index 0000000000..4e5aa47659
--- /dev/null
+++ b/examples/SPIN/nickel/exchange_fit_fcc_ni/exchange_fcc_ni2.dat
@@ -0,0 +1,5 @@
+2.495 8.3
+3.524 -3.99
+4.31 0.998
+4.99 -0.955
+5.56 0.213
diff --git a/examples/SPIN/nickel/exchange_fit_fcc_ni/exchange_fit.py b/examples/SPIN/nickel/exchange_fit_fcc_ni/exchange_fit.py
index dd07e9f295..4046fa45f7 100644
--- a/examples/SPIN/nickel/exchange_fit_fcc_ni/exchange_fit.py
+++ b/examples/SPIN/nickel/exchange_fit_fcc_ni/exchange_fit.py
@@ -16,7 +16,7 @@ rdata, Jdata = np.loadtxt('exchange_fcc_ni.dat', usecols=(0,1), unpack=True)
 plt.plot(rdata, Jdata, 'b-', label='data')
 
 # perform the fit
-popt, pcov = curve_fit(func, rdata, Jdata, bounds=(0, [500.,5.,5.]))
+popt, pcov = curve_fit(func, rdata, Jdata, bounds=([0.0,-1.0,0.0], [100.,5.,5.]))
 plt.plot(rdata, func(rdata, *popt), 'r--', label='fit')
 
 # print the fitted parameters
@@ -24,7 +24,8 @@ print("Parameters: a={:.10} (in meV), b={:.10} (adim), c={:.10} (in Ang)".format
 
 # ploting the result
 plt.xlabel('r_ij')
-pylab.xlim([0,6.5])
+pylab.xlim([0.0,6.5])
+#pylab.ylim([-2.0,10.0])
 plt.ylabel('J_ij')
 plt.legend()
 plt.show()
diff --git a/src/SPIN/README b/src/SPIN/README
new file mode 100644
index 0000000000..e371e39767
--- /dev/null
+++ b/src/SPIN/README
@@ -0,0 +1,25 @@
+The SPIN package enables coupled spin dynamics and molecular 
+dynamics simulations. 
+
+The package provides the following features:
+
+* defining a classical magnetic atomic spin associated to each magnetic
+atom in the system
+* integrating the equations of motion for the coupled spin-lattice system
+* implementing magnetic pair interactions and magnetic forces
+* thermostating and applying a transverse damping to the magnetic spins
+* computing and outputing magnetic quantities
+
+The different options provided by this package are explained in the 
+LAMMPS documentation.
+
+Once you have successfully built LAMMPS with this package, you can test 
+it using one of the input files provided from the examples/SPIN dir:
+
+./lmp_serial < lammps/examples/SPIN/cobalt_hcp/in.spin.cobalt_hcp
+
+
+== Credits and license ==
+
+The person who created this package is Julien Tranchida (jtranch at
+sandia.gov). You can contact him if you have questions.
diff --git a/src/SPIN/atom_vec_spin.h b/src/SPIN/atom_vec_spin.h
index 4177a4c860..99d4a86189 100644
--- a/src/SPIN/atom_vec_spin.h
+++ b/src/SPIN/atom_vec_spin.h
@@ -11,16 +11,6 @@
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
-/* ------------------------------------------------------------------------
-   Contributing authors: Julien Tranchida (SNL)
-                         Aidan Thompson (SNL)
-   
-   Please cite the related publication:
-   Tranchida, J., Plimpton, S. J., Thibaudeau, P., & Thompson, A. P. (2018). 
-   Massively parallel symplectic algorithm for coupled magnetic spin dynamics 
-   and molecular dynamics. arXiv preprint arXiv:1801.10233.
-------------------------------------------------------------------------- */
-
 #ifdef ATOM_CLASS
 
 AtomStyle(spin,AtomVecSpin)
diff --git a/src/SPIN/compute_spin.h b/src/SPIN/compute_spin.h
index 872694cd89..59f0ce2876 100644
--- a/src/SPIN/compute_spin.h
+++ b/src/SPIN/compute_spin.h
@@ -11,16 +11,6 @@
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
-/* ------------------------------------------------------------------------
-   Contributing authors: Julien Tranchida (SNL)
-                         Aidan Thompson (SNL)
-   
-   Please cite the related publication:
-   Tranchida, J., Plimpton, S. J., Thibaudeau, P., & Thompson, A. P. (2018). 
-   Massively parallel symplectic algorithm for coupled magnetic spin dynamics 
-   and molecular dynamics. arXiv preprint arXiv:1801.10233.
-------------------------------------------------------------------------- */
-
 #ifdef COMPUTE_CLASS
 
 ComputeStyle(compute/spin,ComputeSpin)
diff --git a/src/SPIN/fix_langevin_spin.h b/src/SPIN/fix_langevin_spin.h
index ac7506c4c5..0f90a77c14 100644
--- a/src/SPIN/fix_langevin_spin.h
+++ b/src/SPIN/fix_langevin_spin.h
@@ -11,16 +11,6 @@
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
-/* ------------------------------------------------------------------------
-   Contributing authors: Julien Tranchida (SNL)
-                         Aidan Thompson (SNL)
-   
-   Please cite the related publication:
-   Tranchida, J., Plimpton, S. J., Thibaudeau, P., & Thompson, A. P. (2018). 
-   Massively parallel symplectic algorithm for coupled magnetic spin dynamics 
-   and molecular dynamics. arXiv preprint arXiv:1801.10233.
-------------------------------------------------------------------------- */
-
 #ifdef FIX_CLASS
 
 FixStyle(langevin/spin,FixLangevinSpin)
diff --git a/src/SPIN/fix_nve_spin.cpp b/src/SPIN/fix_nve_spin.cpp
index 2d3f73cd77..2f13bdd650 100644
--- a/src/SPIN/fix_nve_spin.cpp
+++ b/src/SPIN/fix_nve_spin.cpp
@@ -27,6 +27,7 @@
 
 #include "atom.h"
 #include "atom_vec.h"
+#include "citeme.h"
 #include "error.h"
 #include "fix_precession_spin.h"
 #include "fix_nve_spin.h"
@@ -50,6 +51,16 @@ using namespace FixConst;
 using namespace MathConst;
 using namespace MathExtra;
 
+static const char cite_fix_nve_spin[] =
+  "fix nve/spin command:\n\n"
+  "@article{tranchida2018massively,\n"
+  "title={Massively parallel symplectic algorithm for coupled magnetic spin "
+  "dynamics and molecular dynamics},\n"
+  "author={Tranchida, J and Plimpton, SJ and Thibaudeau, P and Thompson, AP},\n"
+  "journal={arXiv preprint arXiv:1801.10233},\n"
+  "year={2018}\n"
+  "}\n\n";
+
 enum{NONE};
 
 /* ---------------------------------------------------------------------- */
@@ -60,7 +71,8 @@ FixNVESpin::FixNVESpin(LAMMPS *lmp, int narg, char **arg) :
   backward_stacks(NULL), forward_stacks(NULL),
   pair(NULL), spin_pairs(NULL)
 {
-  
+  if (lmp->citeme) lmp->citeme->add(cite_fix_nve_spin);
+
   if (narg < 4) error->all(FLERR,"Illegal fix/NVE/spin command");  
   
   time_integrate = 1;
diff --git a/src/SPIN/fix_nve_spin.h b/src/SPIN/fix_nve_spin.h
index 686c391299..c7d88ef605 100644
--- a/src/SPIN/fix_nve_spin.h
+++ b/src/SPIN/fix_nve_spin.h
@@ -11,16 +11,6 @@
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
-/* ------------------------------------------------------------------------
-   Contributing authors: Julien Tranchida (SNL)
-                         Aidan Thompson (SNL)
-   
-   Please cite the related publication:
-   Tranchida, J., Plimpton, S. J., Thibaudeau, P., & Thompson, A. P. (2018). 
-   Massively parallel symplectic algorithm for coupled magnetic spin dynamics 
-   and molecular dynamics. arXiv preprint arXiv:1801.10233.
-------------------------------------------------------------------------- */
-
 #ifdef FIX_CLASS
 
 FixStyle(nve/spin,FixNVESpin)
diff --git a/src/SPIN/fix_precession_spin.h b/src/SPIN/fix_precession_spin.h
index 5e1047ff67..2a616b61f0 100644
--- a/src/SPIN/fix_precession_spin.h
+++ b/src/SPIN/fix_precession_spin.h
@@ -11,16 +11,6 @@
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
-/* ------------------------------------------------------------------------
-   Contributing authors: Julien Tranchida (SNL)
-                         Aidan Thompson (SNL)
-   
-   Please cite the related publication:
-   Tranchida, J., Plimpton, S. J., Thibaudeau, P., & Thompson, A. P. (2018). 
-   Massively parallel symplectic algorithm for coupled magnetic spin dynamics 
-   and molecular dynamics. arXiv preprint arXiv:1801.10233.
-------------------------------------------------------------------------- */
-
 #ifdef FIX_CLASS
 
 FixStyle(precession/spin,FixPrecessionSpin)
diff --git a/src/SPIN/pair_spin.h b/src/SPIN/pair_spin.h
index e71f2eb117..94f8433108 100755
--- a/src/SPIN/pair_spin.h
+++ b/src/SPIN/pair_spin.h
@@ -11,8 +11,12 @@
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
+#ifdef PAIR_CLASS
+
 PairStyle(pair/spin,PairSpin)
 
+#else
+
 #ifndef LMP_PAIR_SPIN_H
 #define LMP_PAIR_SPIN_H
 
diff --git a/src/SPIN/pair_spin_dmi.cpp b/src/SPIN/pair_spin_dmi.cpp
index 99b41f77c8..7f07efc9c8 100755
--- a/src/SPIN/pair_spin_dmi.cpp
+++ b/src/SPIN/pair_spin_dmi.cpp
@@ -101,7 +101,6 @@ void PairSpinDmi::settings(int narg, char **arg)
 
 void PairSpinDmi::coeff(int narg, char **arg)
 {
-//  const double hbar = force->hplanck/MY_2PI;
 
   if (!allocated) allocate();
 
@@ -130,15 +129,16 @@ void PairSpinDmi::coeff(int narg, char **arg)
     for (int j = MAX(jlo,i); j <= jhi; j++) {
       cut_spin_dmi[i][j] = rij;
       DM[i][j] = dm;
-      v_dmx[i][j] = dmx;
-      v_dmy[i][j] = dmy;
-      v_dmz[i][j] = dmz;
+      v_dmx[i][j] = dmx * dm;
+      v_dmy[i][j] = dmy * dm;
+      v_dmz[i][j] = dmz * dm;
       setflag[i][j] = 1;
       count++;
     }
   }
   if (count == 0) 
     error->all(FLERR,"Incorrect args in pair_style command"); 
+
 }
 
 /* ----------------------------------------------------------------------
@@ -351,7 +351,6 @@ void PairSpinDmi::compute_single_pair(int ii, double fmi[3])
 
 }
 
-
 /* ----------------------------------------------------------------------
    compute the dmi interaction between spin i and spin j
 ------------------------------------------------------------------------- */
@@ -368,13 +367,16 @@ void PairSpinDmi::compute_dmi(int i, int j, double rsq, double fmi[3], double sp
   if (rsq <= local_cut2) {
     double dmix, dmiy, dmiz;	
 
-    dmix = DM[itype][jtype] * v_dmx[itype][jtype];
-    dmiy = DM[itype][jtype] * v_dmy[itype][jtype];
-    dmiz = DM[itype][jtype] * v_dmz[itype][jtype];
+    //dmix = DM[itype][jtype] * v_dmx[itype][jtype];
+    //dmiy = DM[itype][jtype] * v_dmy[itype][jtype];
+    //dmiz = DM[itype][jtype] * v_dmz[itype][jtype];
+    dmix = v_dmx[itype][jtype];
+    dmiy = v_dmy[itype][jtype];
+    dmiz = v_dmz[itype][jtype];
 
-    fmi[0] -= (spj[1]*dmiz - spj[2]*dmiy);
-    fmi[1] -= (spj[2]*dmix - spj[0]*dmiz);
-    fmi[2] -= (spj[0]*dmiy - spj[1]*dmix);
+    fmi[0] += (spj[1]*dmiz - spj[2]*dmiy);
+    fmi[1] += (spj[2]*dmix - spj[0]*dmiz);
+    fmi[2] += (spj[0]*dmiy - spj[1]*dmix);
 
   }
 }
@@ -390,7 +392,6 @@ void PairSpinDmi::compute_dmi_mech(int i, int j, double fi[3], double spi[3], do
   fi[2] += 0.0;
 }
 
-
 /* ----------------------------------------------------------------------
    allocate all arrays
 ------------------------------------------------------------------------- */
diff --git a/src/SPIN/pair_spin_dmi.h b/src/SPIN/pair_spin_dmi.h
index da9f8d1494..fda38b48fd 100755
--- a/src/SPIN/pair_spin_dmi.h
+++ b/src/SPIN/pair_spin_dmi.h
@@ -11,16 +11,6 @@
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
-/* ------------------------------------------------------------------------
-   Contributing authors: Julien Tranchida (SNL)
-                         Aidan Thompson (SNL)
-   
-   Please cite the related publication:
-   Tranchida, J., Plimpton, S. J., Thibaudeau, P., & Thompson, A. P. (2018). 
-   Massively parallel symplectic algorithm for coupled magnetic spin dynamics 
-   and molecular dynamics. arXiv preprint arXiv:1801.10233.
-------------------------------------------------------------------------- */
-
 #ifdef PAIR_CLASS
 
 PairStyle(spin/dmi,PairSpinDmi)
diff --git a/src/SPIN/pair_spin_exchange.h b/src/SPIN/pair_spin_exchange.h
index 66750743bb..07536a18bd 100755
--- a/src/SPIN/pair_spin_exchange.h
+++ b/src/SPIN/pair_spin_exchange.h
@@ -11,16 +11,6 @@
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
-/* ------------------------------------------------------------------------
-   Contributing authors: Julien Tranchida (SNL)
-                         Aidan Thompson (SNL)
-   
-   Please cite the related publication:
-   Tranchida, J., Plimpton, S. J., Thibaudeau, P., & Thompson, A. P. (2018). 
-   Massively parallel symplectic algorithm for coupled magnetic spin dynamics 
-   and molecular dynamics. arXiv preprint arXiv:1801.10233.
-------------------------------------------------------------------------- */
-
 #ifdef PAIR_CLASS
 
 PairStyle(spin/exchange,PairSpinExchange)
diff --git a/src/SPIN/pair_spin_me.h b/src/SPIN/pair_spin_me.h
index 58ea6b3eda..cd1a93ad6e 100755
--- a/src/SPIN/pair_spin_me.h
+++ b/src/SPIN/pair_spin_me.h
@@ -11,16 +11,6 @@
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
-/* ------------------------------------------------------------------------
-   Contributing authors: Julien Tranchida (SNL)
-                         Aidan Thompson (SNL)
-   
-   Please cite the related publication:
-   Tranchida, J., Plimpton, S. J., Thibaudeau, P., & Thompson, A. P. (2018). 
-   Massively parallel symplectic algorithm for coupled magnetic spin dynamics 
-   and molecular dynamics. arXiv preprint arXiv:1801.10233.
-------------------------------------------------------------------------- */
-
 #ifdef PAIR_CLASS
 
 PairStyle(spin/me,PairSpinMe)
diff --git a/src/SPIN/pair_spin_neel.h b/src/SPIN/pair_spin_neel.h
index 114e1843de..d59f92df26 100755
--- a/src/SPIN/pair_spin_neel.h
+++ b/src/SPIN/pair_spin_neel.h
@@ -11,16 +11,6 @@
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
-/* ------------------------------------------------------------------------
-   Contributing authors: Julien Tranchida (SNL)
-                         Aidan Thompson (SNL)
-   
-   Please cite the related publication:
-   Tranchida, J., Plimpton, S. J., Thibaudeau, P., & Thompson, A. P. (2018). 
-   Massively parallel symplectic algorithm for coupled magnetic spin dynamics 
-   and molecular dynamics. arXiv preprint arXiv:1801.10233.
-------------------------------------------------------------------------- */
-
 #ifdef PAIR_CLASS
 
 PairStyle(spin/neel,PairSpinNeel)
-- 
GitLab