diff --git a/tutorials/4-flowerMD-welding.ipynb b/tutorials/4-flowerMD-welding.ipynb index 7fb9d4d6..c4b71feb 100644 --- a/tutorials/4-flowerMD-welding.ipynb +++ b/tutorials/4-flowerMD-welding.ipynb @@ -33,8 +33,9 @@ "metadata": {}, "outputs": [], "source": [ - " import warnings\n", - "warnings.filterwarnings('ignore')" + "import warnings\n", + "\n", + "warnings.filterwarnings(\"ignore\")" ] }, { @@ -97,9 +98,15 @@ "\n", "system = Pack(\n", " molecules=molecule,\n", - " density=1.1 * u.g/u.cm**3,\n", + " density=1.1 * u.g / u.cm**3,\n", ")\n", - "system.apply_forcefield(r_cut=2.5, force_field=OPLS_AA(), auto_scale=True,remove_charges=True, remove_hydrogens=True)" + "system.apply_forcefield(\n", + " r_cut=2.5,\n", + " force_field=OPLS_AA(),\n", + " auto_scale=True,\n", + " remove_charges=True,\n", + " remove_hydrogens=True,\n", + ")" ] }, { @@ -134,7 +141,7 @@ "source": [ "sim = SlabSimulation.from_system(\n", " system=system,\n", - " interface_axis=(1,0,0),\n", + " interface_axis=(1, 0, 0),\n", " gsd_file_name=\"slab_x_interface.gsd\",\n", ")" ] @@ -232,9 +239,13 @@ } ], "source": [ - "target_box = flowermd.utils.get_target_box_mass_density(density=1.2*u.g/u.cm**3, mass=sim.mass.to(\"g\"))\n", + "target_box = flowermd.utils.get_target_box_mass_density(\n", + " density=1.2 * u.g / u.cm**3, mass=sim.mass.to(\"g\")\n", + ")\n", "\n", - "sim.run_update_volume(final_box_lengths=target_box, n_steps=5e4, kT=5.0, period=100, tau_kt=0.001)" + "sim.run_update_volume(\n", + " final_box_lengths=target_box, n_steps=5e4, kT=5.0, period=100, tau_kt=0.001\n", + ")" ] }, { @@ -294,7 +305,7 @@ } ], "source": [ - "sim.remove_walls(wall_axis=(1,0,0))\n", + "sim.remove_walls(wall_axis=(1, 0, 0))\n", "sim.pickle_forcefield()\n", "sim.flush_writers()" ] @@ -328,7 +339,9 @@ } ], "source": [ - "sim_viewer = FresnelGSD(gsd_file=\"slab_x_interface.gsd\", view_axis=(0, 1, 0), frame=-1)\n", + "sim_viewer = FresnelGSD(\n", + " gsd_file=\"slab_x_interface.gsd\", view_axis=(0, 1, 0), frame=-1\n", + ")\n", "sim_viewer.view()" ] }, @@ -392,7 +405,7 @@ } ], "source": [ - "sim_viewer.view_axis = (1,0,0)\n", + "sim_viewer.view_axis = (1, 0, 0)\n", "sim_viewer.view()" ] }, @@ -428,7 +441,9 @@ } ], "source": [ - "interface = Interface(gsd_files=[\"slab_x_interface.gsd\"], interface_axis=(1, 0, 0), gap=0.05)\n", + "interface = Interface(\n", + " gsd_files=[\"slab_x_interface.gsd\"], interface_axis=(1, 0, 0), gap=0.05\n", + ")\n", "\n", "print(type(interface.hoomd_snapshot))\n", "print(\"Slab number of particles:\", system.n_particles)\n", @@ -512,7 +527,7 @@ " gsd_file_name=\"weld.gsd\",\n", " log_file_name=\"weld_log.txt\",\n", " log_write_freq=500,\n", - " dt=0.0003\n", + " dt=0.0003,\n", ")" ] }, @@ -616,7 +631,9 @@ ], "source": [ "weld_sim.run_NVT(kT=10.0, n_steps=7e4, tau_kt=0.001)\n", - "cooling_ramp = weld_sim.temperature_ramp(n_steps=2e4, kT_start=10.0, kT_final=2.0)\n", + "cooling_ramp = weld_sim.temperature_ramp(\n", + " n_steps=2e4, kT_start=10.0, kT_final=2.0\n", + ")\n", "weld_sim.run_NVT(kT=cooling_ramp, n_steps=2e4, tau_kt=0.001)\n", "weld_sim.save_restart_gsd(\"weld_restart.gsd\")\n", "weld_sim.flush_writers()" @@ -651,10 +668,12 @@ } ], "source": [ - "sim_viewer = FresnelGSD(gsd_file=\"weld.gsd\", view_axis=(0, 1, 0), frame=0, height=12)\n", + "sim_viewer = FresnelGSD(\n", + " gsd_file=\"weld.gsd\", view_axis=(0, 1, 0), frame=0, height=12\n", + ")\n", "weld_colors = np.zeros_like(sim_viewer.positions)\n", - "weld_colors[:weld_colors.shape[0]//2 + 1] = np.array([0.5, 0.25, 0.5])\n", - "weld_colors[weld_colors.shape[0]//2 + 1:] = np.array([0.5, 0.1, 0.1])\n", + "weld_colors[: weld_colors.shape[0] // 2 + 1] = np.array([0.5, 0.25, 0.5])\n", + "weld_colors[weld_colors.shape[0] // 2 + 1 :] = np.array([0.5, 0.1, 0.1])\n", "sim_viewer.colors = weld_colors\n", "sim_viewer.view(width=500, height=500)" ] @@ -737,7 +756,9 @@ "sim_data = np.genfromtxt(\"weld_log.txt\", names=True)\n", "lj_energy = sim_data[\"mdpairLJenergy\"]\n", "time_step = sim_data[\"flowermdmodulesweldingWeldSimulationtimestep\"]\n", - "plt.plot(time_step, lj_energy/interface.hoomd_snapshot.particles.N, linewidth=3)\n", + "plt.plot(\n", + " time_step, lj_energy / interface.hoomd_snapshot.particles.N, linewidth=3\n", + ")\n", "plt.ylabel(\"$\\dfrac{\\epsilon}{N}$\", fontsize=15)\n", "plt.xlabel(\"Time step\", fontsize=15)" ] @@ -775,16 +796,16 @@ "# Open and load the forcefield picke file\n", "with open(\"forcefield.pickle\", \"rb\") as f:\n", " hoomd_forces = pickle.load(f)\n", - " \n", + "\n", "tensile_sim = Tensile(\n", " initial_state=\"weld_restart.gsd\",\n", " forcefield=hoomd_forces,\n", - " tensile_axis=(1,0,0),\n", + " tensile_axis=(1, 0, 0),\n", " gsd_file_name=\"tensile.gsd\",\n", " gsd_write_freq=1000,\n", " log_file_name=\"tensile_log.txt\",\n", " log_write_freq=500,\n", - " fix_ratio=0.30\n", + " fix_ratio=0.30,\n", ")" ] }, @@ -945,7 +966,9 @@ } ], "source": [ - "tensile_sim.run_tensile(n_steps=1e5, strain=0.30, period=500, kT=2.0, tau_kt=0.001)\n", + "tensile_sim.run_tensile(\n", + " n_steps=1e5, strain=0.30, period=500, kT=2.0, tau_kt=0.001\n", + ")\n", "tensile_sim.flush_writers()" ] }, @@ -975,10 +998,12 @@ } ], "source": [ - "sim_viewer = FresnelGSD(gsd_file=\"tensile.gsd\", view_axis=(0, 1, 0), frame=0, height=12)\n", + "sim_viewer = FresnelGSD(\n", + " gsd_file=\"tensile.gsd\", view_axis=(0, 1, 0), frame=0, height=12\n", + ")\n", "weld_colors = np.zeros_like(sim_viewer.positions)\n", - "weld_colors[:weld_colors.shape[0]//2 + 1] = np.array([0.5, 0.25, 0.5])\n", - "weld_colors[weld_colors.shape[0]//2 + 1:] = np.array([0.5, 0.1, 0.1])\n", + "weld_colors[: weld_colors.shape[0] // 2 + 1] = np.array([0.5, 0.25, 0.5])\n", + "weld_colors[weld_colors.shape[0] // 2 + 1 :] = np.array([0.5, 0.1, 0.1])\n", "sim_viewer.colors = weld_colors\n", "sim_viewer.view(width=500, height=500)" ] @@ -1059,7 +1084,7 @@ " new_x = snap.configuration.box[0]\n", " strain = (new_x - initial_x_len) / initial_x_len\n", " energy = snap.log[\"md/pair/LJ/energy\"]\n", - " plt.plot(strain, energy/snap.particles.N, \"ro\")\n", + " plt.plot(strain, energy / snap.particles.N, \"ro\")\n", "\n", "plt.show()" ]