From ea4d266afb14de2f9cf7cc885a7474c4a1002cb4 Mon Sep 17 00:00:00 2001
From: Chris Rackauckas <accounts@chrisrackauckas.com>
Date: Thu, 23 Jun 2022 15:09:54 -0400
Subject: [PATCH] format SciML Style

---
 .JuliaFormatter.toml               |  1 +
 .github/workflows/FormatCheck.yml  | 42 ++++++++++++++++++++++++++++++
 docs/make.jl                       | 24 +++++++----------
 docs/pages.jl                      |  4 +--
 examples/liquid_argon.jl           | 26 ++++++++++--------
 examples/liquid_argon_omm_units.jl | 15 +++++------
 examples/liquid_argon_reduced.jl   | 12 ++++-----
 examples/liquid_argon_sde.jl       | 12 ++++-----
 8 files changed, 87 insertions(+), 49 deletions(-)
 create mode 100644 .JuliaFormatter.toml
 create mode 100644 .github/workflows/FormatCheck.yml

diff --git a/.JuliaFormatter.toml b/.JuliaFormatter.toml
new file mode 100644
index 0000000..453925c
--- /dev/null
+++ b/.JuliaFormatter.toml
@@ -0,0 +1 @@
+style = "sciml"
\ No newline at end of file
diff --git a/.github/workflows/FormatCheck.yml b/.github/workflows/FormatCheck.yml
new file mode 100644
index 0000000..2a3517a
--- /dev/null
+++ b/.github/workflows/FormatCheck.yml
@@ -0,0 +1,42 @@
+name: format-check
+
+on:
+  push:
+    branches:
+      - 'master'
+      - 'release-'
+    tags: '*'
+  pull_request:
+
+jobs:
+  build:
+    runs-on: ${{ matrix.os }}
+    strategy:
+      matrix:
+        julia-version: [1]
+        julia-arch: [x86]
+        os: [ubuntu-latest]
+    steps:
+      - uses: julia-actions/setup-julia@latest
+        with:
+          version: ${{ matrix.julia-version }}
+
+      - uses: actions/checkout@v1
+      - name: Install JuliaFormatter and format
+        # This will use the latest version by default but you can set the version like so:
+        #
+        # julia  -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter", version="0.13.0"))'
+        run: |
+          julia  -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter"))'
+          julia  -e 'using JuliaFormatter; format(".", verbose=true)'
+      - name: Format check
+        run: |
+          julia -e '
+          out = Cmd(`git diff --name-only`) |> read |> String
+          if out == ""
+              exit(0)
+          else
+              @error "Some files have not been formatted !!!"
+              write(stdout, out)
+              exit(1)
+          end'
diff --git a/docs/make.jl b/docs/make.jl
index 3cbe7d3..a899f75 100644
--- a/docs/make.jl
+++ b/docs/make.jl
@@ -2,18 +2,14 @@ using Documenter, NBodySimulator
 
 include("pages.jl")
 
-makedocs(
-    sitename="NbodySimulator.jl",
-    authors="Chris Rackauckas",
-    modules=[NBodySimulator],
-    clean=true,doctest=false,
-    format = Documenter.HTML(analytics = "UA-90474609-3",
-                             assets = ["assets/favicon.ico"],
-                             canonical="https://nbodysimulator.sciml.ai/stable/"),
-    pages=pages
-)
+makedocs(sitename = "NbodySimulator.jl",
+         authors = "Chris Rackauckas",
+         modules = [NBodySimulator],
+         clean = true, doctest = false,
+         format = Documenter.HTML(analytics = "UA-90474609-3",
+                                  assets = ["assets/favicon.ico"],
+                                  canonical = "https://nbodysimulator.sciml.ai/stable/"),
+         pages = pages)
 
-deploydocs(
-   repo = "github.com/SciML/NBodySimulator.jl.git";
-   push_preview = true
-)
\ No newline at end of file
+deploydocs(repo = "github.com/SciML/NBodySimulator.jl.git";
+           push_preview = true)
diff --git a/docs/pages.jl b/docs/pages.jl
index 7b7d575..385c690 100644
--- a/docs/pages.jl
+++ b/docs/pages.jl
@@ -1,7 +1,7 @@
 # Put in a separate page so it can be used by SciMLDocs.jl
 
-pages=[
+pages = [
     "Home" => "index.md",
     "examples.md",
-    "nbodysimulator.md"
+    "nbodysimulator.md",
 ]
diff --git a/examples/liquid_argon.jl b/examples/liquid_argon.jl
index 50c4675..4164326 100644
--- a/examples/liquid_argon.jl
+++ b/examples/liquid_argon.jl
@@ -3,23 +3,27 @@ using NBodySimulator, StaticArrays
 function generate_bodies_in_line(n::Int, m::Real, v_dev::Real, L::Real)
     dL = L / (ceil(n^(1 / 3)))
     n_line = floor(Int, L / dL)
-    rng = MersenneTwister(n);
+    rng = MersenneTwister(n)
     velocities = v_dev * randn(rng, Float64, (3, n_line))
     bodies = MassBody[]
     x = y = L / 2
-    for i = 1:n_line      
+    for i in 1:n_line
         r = SVector(x, y, i * dL)
-        v = SVector{3}(velocities[:,i])
+        v = SVector{3}(velocities[:, i])
         body = MassBody(r, v, m)
-        push!(bodies, body)  
+        push!(bodies, body)
     end
     return bodies
 end
 
 function generate_random_directions(n::Int)
-    theta = acos.(1 - 2 * rand(n));
-    phi = 2 * pi * rand(n);
-    directions = [@SVector [sin(theta[i]) .* cos(phi[i]), sin(theta[i]) .* sin(phi[i]), cos(theta[i])] for i = 1:n]
+    theta = acos.(1 - 2 * rand(n))
+    phi = 2 * pi * rand(n)
+    directions = [@SVector [
+                      sin(theta[i]) .* cos(phi[i]),
+                      sin(theta[i]) .* sin(phi[i]),
+                      cos(theta[i]),
+                  ] for i in 1:n]
 end
 
 units = :real
@@ -33,8 +37,8 @@ const σ = 3.4e-10 # m
 const ρ = 1374 # kg/m^3
 const m = 39.95 * 1.6747 * 1e-27 # kg
 const N = 216#floor(Int, ρ * L^3 / m)
-const L = (m*N/ρ)^(1/3)#10.229σ
-const R = 0.5*L   
+const L = (m * N / ρ)^(1 / 3)#10.229σ
+const R = 0.5 * L
 const v_dev = sqrt(kb * T / m)
 const τ = 0.5e-15 # σ/v
 const t1 = 0τ
@@ -48,7 +52,7 @@ pbc = CubicPeriodicBoundaryConditions(L)
 lj_system = PotentialNBodySystem(bodies, Dict(:lennard_jones => jl_parameters));
 simulation = NBodySimulation(lj_system, (t1, t2), pbc, kb);
 #result = run_simulation(simulation, Tsit5())
-result = @time run_simulation(simulation, VelocityVerlet(), dt=τ)
+result = @time run_simulation(simulation, VelocityVerlet(), dt = τ)
 
 #=
 using Plots
@@ -95,4 +99,4 @@ write(file, "ts", ts)
 write(file, "grf", grf)
 write(file, "dr2", dr2)
 close(file)
-=#
\ No newline at end of file
+=#
diff --git a/examples/liquid_argon_omm_units.jl b/examples/liquid_argon_omm_units.jl
index 88b291b..5e940da 100644
--- a/examples/liquid_argon_omm_units.jl
+++ b/examples/liquid_argon_omm_units.jl
@@ -6,11 +6,11 @@ const T0 = 90.0 # °K
 const kb = 8.3144598e-3 # kJ/(K*mol)
 const ϵ = T * kb
 const σ = 0.34 # nm
-const ρ = 1374/1.6747# Da/nm^3
+const ρ = 1374 / 1.6747# Da/nm^3
 const m = 39.95# Da
 const N = 8
-const L = (m*N/ρ)^(1/3)#10.229σ
-const R = 0.5*L   
+const L = (m * N / ρ)^(1 / 3)#10.229σ
+const R = 0.5 * L
 const v_dev = sqrt(kb * T / m)
 const bodies = generate_bodies_in_cell_nodes(N, m, v_dev, L)
 
@@ -28,15 +28,14 @@ const pbc = CubicPeriodicBoundaryConditions(L)
 const simulation = NBodySimulation(lj_system, (t1, t2), pbc, thermostat, kb);
 #result = @time run_simulation(simulation, VelocityVerlet(), dt=τ)
 #result = @time run_simulation_sde(simulation, ISSEM(symplectic=true,theta=0.5))
-result = @time run_simulation(simulation, EM(), dt=τ)
+result = @time run_simulation(simulation, EM(), dt = τ)
 
 #(rs, grf) = rdf(result)
 #(ts, dr2) = msd(result)
 
-t = t1:τ:result.solution.t[end-1]
+t = t1:τ:result.solution.t[end - 1]
 temper = @time temperature.(result, t)
 
-
 #using Plots
 #pl=plot(t, temper, ylim=[0,200], xlabel="t, ps", ylabel = "T, °K", label="Temperature, °K", linewidth=2)
 #plot!(pl, t, T0*ones(length(t)), label = "90 °K", linewidth=2)
@@ -44,7 +43,6 @@ temper = @time temperature.(result, t)
 #plot!(pl, title="Berendsen thermostat at tau=$(thermostat.τ) ps")
 #plot!(pl, title="Nose-Hoover thermostat at tau=$(thermostat.τ) ps")
 
-
 time_now = Dates.format(now(), "yyyy_mm_dd_HH_MM_SS")
 Nactual = length(bodies)
 timesteps = round(length(result.solution.t))
@@ -54,7 +52,6 @@ timesteps = round(length(result.solution.t))
 #using JLD
 #save("d:/nosehoover thermostat for water liquid argon $T0 and $(thermostat.τ) _$time_now.jld", "t",t, "temper", temper, "T0", T0, "τ", thermostat.τ)
 
-
 #=
 using MAT
 
@@ -74,4 +71,4 @@ end
 #write(file, "grf", grf)
 #write(file, "dr2", dr2)
 close(file)
-=#
\ No newline at end of file
+=#
diff --git a/examples/liquid_argon_reduced.jl b/examples/liquid_argon_reduced.jl
index 561b5ec..506c4a4 100644
--- a/examples/liquid_argon_reduced.jl
+++ b/examples/liquid_argon_reduced.jl
@@ -7,8 +7,8 @@ const σ = 3.4e-10 # m
 const ρ = 1374 # kg/m^3
 const m = 39.95 * 1.6747 * 1e-27 # kg
 const N = 216#floor(Int, ρ * L^3 / m)
-const L = (m*N/ρ)^(1/3)#10.229σ
-const R = 2.25σ   
+const L = (m * N / ρ)^(1 / 3)#10.229σ
+const R = 2.25σ
 const v_dev = sqrt(kb * T / m)
 const τ = 0.5e-15 # σ/v, fs
 const t1 = 0.0
@@ -26,9 +26,10 @@ const _t2 = t2 * sqrt(ϵ / m) / σ
 bodies = generate_bodies_in_cell_nodes(N, _m, _v, _L)
 parameters = LennardJonesParameters(_ϵ, _σ, _R)
 lj_system = PotentialNBodySystem(bodies, Dict(:lennard_jones => parameters));
-simulation = NBodySimulation(lj_system, (_t1, _t2), CubicPeriodicBoundaryConditions(_L), _ϵ/T);
+simulation = NBodySimulation(lj_system, (_t1, _t2), CubicPeriodicBoundaryConditions(_L),
+                             _ϵ / T);
 #result = run_simulation(simulation, Tsit5())
-result = @time run_simulation(simulation, VelocityVerlet(), dt=_τ)
+result = @time run_simulation(simulation, VelocityVerlet(), dt = _τ)
 
 #(rs, grf) = rdf(result)
 #(ts, dr2) = msd(result)
@@ -37,9 +38,8 @@ result = @time run_simulation(simulation, VelocityVerlet(), dt=_τ)
 #plot(rs, grf, xlim=[0, 0.4999_L], label=["Radial distribution function"],ylabel="g(r)", xlabel="r")
 #plot(rs/_σ, grf, xlim=[0, 0.4999_L/_σ], label=["Radial distribution function"],ylabel="g(r)", xlabel="r/sigma")
 
-
 #time_now = Dates.format(now(), "yyyy_mm_dd_HH_MM_SS")
 #Nactual = length(bodies)
 #timesteps = round(length(result.solution.t))
 
-#@time save_to_pdb(result, "D:/liquid argon simulation $Nactual molecules and $timesteps steps $time_now.pdb" )
\ No newline at end of file
+#@time save_to_pdb(result, "D:/liquid argon simulation $Nactual molecules and $timesteps steps $time_now.pdb" )
diff --git a/examples/liquid_argon_sde.jl b/examples/liquid_argon_sde.jl
index f53352f..59a3203 100644
--- a/examples/liquid_argon_sde.jl
+++ b/examples/liquid_argon_sde.jl
@@ -6,11 +6,11 @@ T0 = 90
 kb = 8.3144598e-3 # kJ/(K*mol)
 ϵ = T * kb
 σ = 0.34 # nm
-ρ = 1374/1.6747# Da/nm^3
+ρ = 1374 / 1.6747# Da/nm^3
 m = 39.95# Da
 N = 216
-L = (m*N/ρ)^(1/3)#10.229σ
-R = 0.5*L   
+L = (m * N / ρ)^(1 / 3)#10.229σ
+R = 0.5 * L
 v_dev = sqrt(kb * T / m)
 bodies = generate_bodies_in_cell_nodes(N, m, v_dev, L)
 
@@ -26,14 +26,13 @@ thermostat = LangevinThermostat(T0, 10.0)
 pbc = CubicPeriodicBoundaryConditions(L)
 simulation = NBodySimulation(lj_system, (t1, t2), pbc, thermostat, kb);
 #result = @time run_simulation(simulation, VelocityVerlet(), dt=τ)
-result = @time run_simulation_sde(simulation, EM(),  dt=τ)
+result = @time run_simulation_sde(simulation, EM(), dt = τ)
 
 #=
 time_now = Dates.format(now(), "yyyy_mm_dd_HH_MM_SS")
 Nactual = length(bodies)
 timesteps = round(length(result.solution.t))
 
-
 using Plots
 t = t1:τ:result.solution.t[end-1]
 temper = temperature.(result, t)
@@ -41,7 +40,6 @@ pl=plot(t, temper, ylim=[0,500], xlabel="t, ps", ylabel = "T, °K", label="Tempe
 plot!(pl, t, T0*ones(length(t)), label = "$T0 °K", linewidth=2)
 plot!(pl, title="Langevin thermostat at gamma=$(thermostat.γ)  1/ps")
 
-
 using JLD
 save("d:/$(typeof(thermostat)) thermostat for water $T0 _$time_now.jld", "t",t, "temper", temper, "T0", T0, "thermostat", thermostat)
-=#
\ No newline at end of file
+=#