diff --git a/docs/.Contributors.rst.swp b/docs/.Contributors.rst.swp new file mode 100644 index 0000000..5b77637 Binary files /dev/null and b/docs/.Contributors.rst.swp differ diff --git a/docs/API.rst b/docs/API.rst new file mode 100644 index 0000000..da18b59 --- /dev/null +++ b/docs/API.rst @@ -0,0 +1,90 @@ +.. _API: + +================= +API Documentation +================= + +Initialize the system ++++++++++++++++++++++ + +For initialize the sysetm, the ``generate_initial_state()`` will generate an initial state either in a random way or import from a *.xyz* file. + +.. autosummary:: + :toctree: autosummary + + mc_lj_potential.generate_initial_state + +.. tip:: + + The *.xyz* file will give the coordinates of all the particles. If the method is *random*, num_particles and box_length are required arguments. + +Class Box ++++++++++ + +This is the class to generate a box, with the particles parameters. + +.. autosummary:: + :toctree: autosummary + + mc_lj_potential.Box + +In the class, we have functions as follows: + +.. autosummary:: + :toctree: autosummary + + mc_lj_potential.Box.wrap + mc_lj_potential.Box.minimum_image_distance + +And we set the volume and num_particles as properties, can be called as: + +.. autosummary:: + :toctree: autosummary + + mc_lj_potential.Box.volume + mc_lj_potential.Box.num_particles + + +Class MCState ++++++++++++++ + +In the class ``MCState``, we will have functions for the energies in the defined system: + +.. autosummary:: + :toctree: autosummary + + mc_lj_potential.MCState + +In the class, we can calculate total pair energy, tail correction, unit energy and particle energy by functions as follows: + +.. autosummary:: + :toctree: autosummary + + mc_lj_potential.MCState.calculate_total_pair_energy + mc_lj_potential.MCState.calculate_tail_correction + mc_lj_potential.MCState.calculate_unit_energy + mc_lj_potential.MCState.get_particle_energy + + +Monte Carlo Steps ++++++++++++++++++ + +After that the Monte Carlo will determine the acceptance of each movement with ``accept_or_reject()``: + +.. autosummary:: + :toctree: autosummary + + mc_lj_potential.accept_or_reject + + +Optimization +++++++++++++ + +Optimization of the scale of displacement can be done by ``adjust_displacement()``: + +.. autosummary:: + :toctree: autosummary + + mc_lj_potential.adjust_displacement + + diff --git a/docs/Acknowledgement.rst b/docs/Acknowledgement.rst new file mode 100644 index 0000000..50fddcc --- /dev/null +++ b/docs/Acknowledgement.rst @@ -0,0 +1,10 @@ +.. _Acknowledgement: + +=============== +Acknowledgement +=============== + +MolSSI Software Summer School +----------------------------- + +Detailed information is at `MolSSI `_. diff --git a/docs/Contributors.rst b/docs/Contributors.rst new file mode 100644 index 0000000..2111de4 --- /dev/null +++ b/docs/Contributors.rst @@ -0,0 +1,33 @@ +.. _Contributors: + +============ +Contributors +============ + + +Arpit Bansal + | arpitban@buffalo.edu + | University at Buffalo (SUNY) + + + +Govinda KC + | gbkc@miners.utep.edu + | University of Texas at El Paso + + + +Madison Berger + | madisonberger@my.unt.edu + | University: University of North Texas + + +Rishabh D Guha + | rdguha@ncsu.edu + | UnivNorth Carolina State University + + +Yuan Zhou + | yuanzhou@umich.edu + | University of Michigan, Ann Arbor + diff --git a/docs/Makefile b/docs/Makefile index cad8e81..e871520 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -17,4 +17,4 @@ help: # Catch-all target: route all unknown targets to Sphinx using the new # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). %: Makefile - @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) \ No newline at end of file + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/README.md b/docs/README.md index ec8aa3e..3858dcc 100644 --- a/docs/README.md +++ b/docs/README.md @@ -15,4 +15,4 @@ make html ``` The compiled docs will be in the `_build` directory and can be viewed by opening `index.html` (which may itself -be inside a directory called `html/` depending on what version of Sphinx is installed). \ No newline at end of file +be inside a directory called `html/` depending on what version of Sphinx is installed). diff --git a/docs/Tutorial.rst b/docs/Tutorial.rst new file mode 100644 index 0000000..7a5b2d9 --- /dev/null +++ b/docs/Tutorial.rst @@ -0,0 +1,139 @@ +.. _Tutorial: + +======== +Tutorial +======== + +**mc_lj_potential** is a python package to carry out Monte Carlo simulation of Lennard Jones particles. By calling different functions in the package, users can get the total pair energy, tail correction, particle energy and unit energy of a defined system with specific cubic box size, number of particles and their coordinates. + +generate_initial_state +++++++++++++++++++++++ + +.. code-block:: python + + #mc_lj.py + import mc_lj_potential as mc + import numpy as np + np.random.seed(123) + num_particles = 100 + box_length = 10.0 + coordinates = mc.generate_initial_state(method = 'random', num_particles = num_particles, box_length = box_length) + print(coordinates) + +.. note:: + + Attention: The ``np.random.seed(123)`` here is used to make sure users can get the same results by following the tutorials below. There is no need to generate the random seed forcely in users' simulation. + +save the script as mc_lj.py, run it, then the output is 100 random coordinates: + +.. code-block:: bash + + ~/my_project$ python mc_lj.py + [[-6.46469186e+00 -2.36139335e+00 -1.76851454e+00] + [-5.01314769e+00 -6.69468970e+00 -3.73106460e+00] + [-9.30764198e+00 -6.34829739e+00 -4.30931901e+00] + [-3.42117518e+00 -2.93178016e+00 -6.79049707e+00] + [-3.88572245e+00 -9.67789661e-02 -3.48044255e+00] + [-6.87995406e+00 -1.32491730e+00 -1.25451756e+00] + [-4.81551374e+00 -4.81827587e+00 -5.84400959e+00] + ... + +.. note:: + + User are allow to import coordinates from a file as well. Instead of ``mc.generate_initial_state(method = 'random', + num_particles = num_particles, box_length = box_length)``, use + ``mc.generate_initial_state(method = 'file', box_length = box_length)``. + +calculate energy in the system +++++++++++++++++++++++++++++++ + +In order to calculate the energy in the system, we need to initialize our box into unit box with ``wrap()`` and ``minimum_image_distance()``. + +.. code-block:: python + + box = mc.Box(coordinates = coordinates, box_length = box_length) + print(box.coordinates) + +add this into mc_lj.py, run it: + +.. code-block:: bash + + ~/my_project$ python mc_lj.py + [[-6.46469186e+00 -2.36139335e+00 -1.76851454e+00] + [-5.01314769e+00 -6.69468970e+00 -3.73106460e+00] + [-9.30764198e+00 -6.34829739e+00 -4.30931901e+00] + [-3.42117518e+00 -2.93178016e+00 -6.79049707e+00] + [-3.88572245e+00 -9.67789661e-02 -3.48044255e+00] + [-6.87995406e+00 -1.32491730e+00 -1.25451756e+00] + [-4.81551374e+00 -4.81827587e+00 -5.84400959e+00] + ... + +it will update our coordinates into the box. + +calculate total pair energy +--------------------------- + +.. code-block:: python + + mcs = mc.MCState(box1 = box, cutoff = 3.0) + total_pair_energy = mcs.calculate_total_energy() + print("total pair energy of the system is",total_pair_energy) + +The output is: + +.. code-block:: bash + + ~/my_project$ python mc_lj.py + total pair energy of the system is 18677707323853.145 + + +calculate tail correction +------------------------- + +.. code-block:: python + + tail_correction = mcs.calculate_tail_correction() + print("tail correction of the system is", tail_correction) + +The output is: + +.. code-block:: bash + + ~/my_project$ python mc_lj.py + tail correction of the system is -3.101388808502446 + + +calculate unit energy +--------------------- + +.. code-block:: python + + unit_energy = mcs.calculate_unit_energy() + print("unit energy of the system is",unit_energy) + +The output is: + +.. code-block:: bash + + ~/my_project$ python mc_lj.py + unit energy of the system is 186777073238.50043 + + +get particle energy +------------------- + +For example, the particle energy of the first particle can be obtained by ``mcs.get_particle_energy(0)`` where the **index 0** means the first particle in the system. + +.. code-block:: python + + particle_energy = mcs.get_particle_energy(0) + print("particle energy of the first particle is",particle_energy) + +The output is: + +.. code-block:: bash + + ~/my_project$ python mc_lj.py + particle energy of the first particle is 12.663401162199152 + + diff --git a/docs/autosummary/mc_lj_potential.Box.minimum_image_distance.rst b/docs/autosummary/mc_lj_potential.Box.minimum_image_distance.rst new file mode 100644 index 0000000..0c43a96 --- /dev/null +++ b/docs/autosummary/mc_lj_potential.Box.minimum_image_distance.rst @@ -0,0 +1,6 @@ +mc\_lj\_potential.Box.minimum\_image\_distance +============================================== + +.. currentmodule:: mc_lj_potential + +.. automethod:: Box.minimum_image_distance \ No newline at end of file diff --git a/docs/autosummary/mc_lj_potential.Box.num_particles.rst b/docs/autosummary/mc_lj_potential.Box.num_particles.rst new file mode 100644 index 0000000..58ac7c4 --- /dev/null +++ b/docs/autosummary/mc_lj_potential.Box.num_particles.rst @@ -0,0 +1,6 @@ +mc\_lj\_potential.Box.num\_particles +==================================== + +.. currentmodule:: mc_lj_potential + +.. autoproperty:: Box.num_particles \ No newline at end of file diff --git a/docs/autosummary/mc_lj_potential.Box.rst b/docs/autosummary/mc_lj_potential.Box.rst new file mode 100644 index 0000000..8f6d353 --- /dev/null +++ b/docs/autosummary/mc_lj_potential.Box.rst @@ -0,0 +1,31 @@ +mc\_lj\_potential.Box +===================== + +.. currentmodule:: mc_lj_potential + +.. autoclass:: Box + + + .. automethod:: __init__ + + + .. rubric:: Methods + + .. autosummary:: + + ~Box.__init__ + ~Box.minimum_image_distance + ~Box.wrap + + + + + + .. rubric:: Attributes + + .. autosummary:: + + ~Box.num_particles + ~Box.volume + + \ No newline at end of file diff --git a/docs/autosummary/mc_lj_potential.Box.volume.rst b/docs/autosummary/mc_lj_potential.Box.volume.rst new file mode 100644 index 0000000..c7fe50d --- /dev/null +++ b/docs/autosummary/mc_lj_potential.Box.volume.rst @@ -0,0 +1,6 @@ +mc\_lj\_potential.Box.volume +============================ + +.. currentmodule:: mc_lj_potential + +.. autoproperty:: Box.volume \ No newline at end of file diff --git a/docs/autosummary/mc_lj_potential.Box.wrap.rst b/docs/autosummary/mc_lj_potential.Box.wrap.rst new file mode 100644 index 0000000..a736909 --- /dev/null +++ b/docs/autosummary/mc_lj_potential.Box.wrap.rst @@ -0,0 +1,6 @@ +mc\_lj\_potential.Box.wrap +========================== + +.. currentmodule:: mc_lj_potential + +.. automethod:: Box.wrap \ No newline at end of file diff --git a/docs/autosummary/mc_lj_potential.MCState.calculate_tail_correction.rst b/docs/autosummary/mc_lj_potential.MCState.calculate_tail_correction.rst new file mode 100644 index 0000000..3b57b65 --- /dev/null +++ b/docs/autosummary/mc_lj_potential.MCState.calculate_tail_correction.rst @@ -0,0 +1,6 @@ +mc\_lj\_potential.MCState.calculate\_tail\_correction +===================================================== + +.. currentmodule:: mc_lj_potential + +.. automethod:: MCState.calculate_tail_correction \ No newline at end of file diff --git a/docs/autosummary/mc_lj_potential.MCState.calculate_total_pair_energy.rst b/docs/autosummary/mc_lj_potential.MCState.calculate_total_pair_energy.rst new file mode 100644 index 0000000..b0852b5 --- /dev/null +++ b/docs/autosummary/mc_lj_potential.MCState.calculate_total_pair_energy.rst @@ -0,0 +1,6 @@ +mc\_lj\_potential.MCState.calculate\_total\_pair\_energy +======================================================== + +.. currentmodule:: mc_lj_potential + +.. automethod:: MCState.calculate_total_pair_energy \ No newline at end of file diff --git a/docs/autosummary/mc_lj_potential.MCState.calculate_unit_energy.rst b/docs/autosummary/mc_lj_potential.MCState.calculate_unit_energy.rst new file mode 100644 index 0000000..8f569f4 --- /dev/null +++ b/docs/autosummary/mc_lj_potential.MCState.calculate_unit_energy.rst @@ -0,0 +1,6 @@ +mc\_lj\_potential.MCState.calculate\_unit\_energy +================================================= + +.. currentmodule:: mc_lj_potential + +.. automethod:: MCState.calculate_unit_energy \ No newline at end of file diff --git a/docs/autosummary/mc_lj_potential.MCState.get_particle_energy.rst b/docs/autosummary/mc_lj_potential.MCState.get_particle_energy.rst new file mode 100644 index 0000000..f47b4a5 --- /dev/null +++ b/docs/autosummary/mc_lj_potential.MCState.get_particle_energy.rst @@ -0,0 +1,6 @@ +mc\_lj\_potential.MCState.get\_particle\_energy +=============================================== + +.. currentmodule:: mc_lj_potential + +.. automethod:: MCState.get_particle_energy \ No newline at end of file diff --git a/docs/autosummary/mc_lj_potential.MCState.rst b/docs/autosummary/mc_lj_potential.MCState.rst new file mode 100644 index 0000000..f0c0372 --- /dev/null +++ b/docs/autosummary/mc_lj_potential.MCState.rst @@ -0,0 +1,27 @@ +mc\_lj\_potential.MCState +========================= + +.. currentmodule:: mc_lj_potential + +.. autoclass:: MCState + + + .. automethod:: __init__ + + + .. rubric:: Methods + + .. autosummary:: + + ~MCState.__init__ + ~MCState.calculate_tail_correction + ~MCState.calculate_total_pair_energy + ~MCState.calculate_unit_energy + ~MCState.get_particle_energy + ~MCState.lennard_jones_potential + + + + + + diff --git a/docs/autosummary/mc_lj_potential.accept_or_reject.rst b/docs/autosummary/mc_lj_potential.accept_or_reject.rst new file mode 100644 index 0000000..ffe1566 --- /dev/null +++ b/docs/autosummary/mc_lj_potential.accept_or_reject.rst @@ -0,0 +1,6 @@ +mc\_lj\_potential.accept\_or\_reject +==================================== + +.. currentmodule:: mc_lj_potential + +.. autofunction:: accept_or_reject diff --git a/docs/autosummary/mc_lj_potential.adjust_displacement.rst b/docs/autosummary/mc_lj_potential.adjust_displacement.rst new file mode 100644 index 0000000..d1b6cf5 --- /dev/null +++ b/docs/autosummary/mc_lj_potential.adjust_displacement.rst @@ -0,0 +1,6 @@ +mc\_lj\_potential.adjust\_displacement +====================================== + +.. currentmodule:: mc_lj_potential + +.. autofunction:: adjust_displacement \ No newline at end of file diff --git a/docs/autosummary/mc_lj_potential.generate_initial_state.rst b/docs/autosummary/mc_lj_potential.generate_initial_state.rst new file mode 100644 index 0000000..90b3934 --- /dev/null +++ b/docs/autosummary/mc_lj_potential.generate_initial_state.rst @@ -0,0 +1,6 @@ +mc\_lj\_potential.generate\_initial\_state +========================================== + +.. currentmodule:: mc_lj_potential + +.. autofunction:: generate_initial_state \ No newline at end of file diff --git a/docs/conf.py b/docs/conf.py index f3db03d..e64aa5a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -5,9 +5,9 @@ # This file does only contain a selection of the most common options. For a # full list see the documentation: # http://www.sphinx-doc.org/en/stable/config - +​ # -- Path setup -------------------------------------------------------------- - +​ # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. @@ -15,81 +15,86 @@ # import os # import sys # sys.path.insert(0, os.path.abspath('.')) - - +​ +​ # -- Project information ----------------------------------------------------- - +​ project = 'mc_lj_potential' -copyright = ("2019, Arpit Bansal. Project structure based on the " +copyright = ("2019, Arpit Bansal, Govinda KC, Madison Berge, Rishabh D Guha, Yuan Zhou. Project structure based on the " "Computational Molecular Science Python Cookiecutter version 1.0") -author = 'Arpit Bansal' +author = 'Arpit Bansal, Govinda KC, Madison Berge, Rishabh D Guha, Yuan Zhou.' + +======= # The short X.Y version version = '' # The full version, including alpha/beta/rc tags release = '' - - +​ +​ # -- General configuration --------------------------------------------------- - +​ # If your documentation needs a minimal Sphinx version, state it here. # # needs_sphinx = '1.0' - +​ # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ 'sphinx.ext.autodoc', + 'sphinx.ext.autosummary', 'sphinx.ext.mathjax', + 'sphinx.ext.napoleon', ] +autosummary_generate = True # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] - +​ # The suffix(es) of source filenames. # You can specify multiple suffix as a list of string: # # source_suffix = ['.rst', '.md'] source_suffix = '.rst' - +​ # The master toctree document. master_doc = 'index' - +​ # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. language = None - +​ # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This pattern also affects html_static_path and html_extra_path . exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] - +​ # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' - - +​ +​ # -- Options for HTML output ------------------------------------------------- - +​ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # html_theme = 'sphinx_rtd_theme' - +​ # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. # # html_theme_options = {} - +​ # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['_static'] - +​ # Custom sidebar templates, must be a dictionary that maps document names # to template names. # @@ -99,34 +104,34 @@ # 'searchbox.html']``. # # html_sidebars = {} - - +​ +​ # -- Options for HTMLHelp output --------------------------------------------- - +​ # Output file base name for HTML help builder. htmlhelp_basename = 'mc_lj_potentialdoc' - - +​ +​ # -- Options for LaTeX output ------------------------------------------------ - +​ latex_elements = { # The paper size ('letterpaper' or 'a4paper'). # # 'papersize': 'letterpaper', - +​ # The font size ('10pt', '11pt' or '12pt'). # # 'pointsize': '10pt', - +​ # Additional stuff for the LaTeX preamble. # # 'preamble': '', - +​ # Latex figure (float) alignment # # 'figure_align': 'htbp', } - +​ # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). @@ -134,20 +139,20 @@ (master_doc, 'mc_lj_potential.tex', 'mc_lj_potential Documentation', 'mc_lj_potential', 'manual'), ] - - +​ +​ # -- Options for manual page output ------------------------------------------ - +​ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ (master_doc, 'mc_lj_potential', 'mc_lj_potential Documentation', [author], 1) ] - - +​ +​ # -- Options for Texinfo output ---------------------------------------------- - +​ # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) @@ -156,6 +161,6 @@ author, 'mc_lj_potential', 'A python package to carry out Monte Carlo simulation of Lennard Jones particles.', 'Miscellaneous'), ] - - +​ +​ # -- Extension configuration ------------------------------------------------- diff --git a/docs/index.rst b/docs/index.rst index 52c71af..ea8d0d7 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -7,29 +7,26 @@ mc_lj_potential =============== -.. only::html - -|Citing-mc_lj_potential| -|Read-the-Docs| -|Contributors| -|License| - - .. |Read-the-Docs| image:: https://img.shields.io/readthedocs/hoomd-blue/stable.svg - :target: https://hoomd-blue.readthedocs.io/en/stable/?badge=stable - .. |Contributors| image:: https://img.shields.io/github/contributors-anon/glotzerlab/hoomd-blue.svg?style=flat - :target: https://hoomd-blue.readthedocs.io/en/stable/credits.html - .. |License| image:: https://img.shields.io/badge/license-BSD--3--Clause-green.svg - :target: https://github.com/glotzerlab/hoomd-blue/blob/maint/LICENSE - -**mc_lj_potential** is used for Monte Carlo simulation of fluid based on lennard jones potential. +**mc_lj_potential** carries out Monte Carlo simulation for Lennard Jones particles. + +Available techniques: + - total pair energy + - tail correction + - unit energy + - particle energy + .. toctree:: - + :maxdepth: 2 + :caption: Contents: + API + Contributors + Acknowledgement + Tutorial Indices and tables ================== - * :ref:`genindex` * :ref:`modindex` * :ref:`search` diff --git a/docs/tutorial.rst b/docs/tutorial.rst new file mode 100644 index 0000000..7a5b2d9 --- /dev/null +++ b/docs/tutorial.rst @@ -0,0 +1,139 @@ +.. _Tutorial: + +======== +Tutorial +======== + +**mc_lj_potential** is a python package to carry out Monte Carlo simulation of Lennard Jones particles. By calling different functions in the package, users can get the total pair energy, tail correction, particle energy and unit energy of a defined system with specific cubic box size, number of particles and their coordinates. + +generate_initial_state +++++++++++++++++++++++ + +.. code-block:: python + + #mc_lj.py + import mc_lj_potential as mc + import numpy as np + np.random.seed(123) + num_particles = 100 + box_length = 10.0 + coordinates = mc.generate_initial_state(method = 'random', num_particles = num_particles, box_length = box_length) + print(coordinates) + +.. note:: + + Attention: The ``np.random.seed(123)`` here is used to make sure users can get the same results by following the tutorials below. There is no need to generate the random seed forcely in users' simulation. + +save the script as mc_lj.py, run it, then the output is 100 random coordinates: + +.. code-block:: bash + + ~/my_project$ python mc_lj.py + [[-6.46469186e+00 -2.36139335e+00 -1.76851454e+00] + [-5.01314769e+00 -6.69468970e+00 -3.73106460e+00] + [-9.30764198e+00 -6.34829739e+00 -4.30931901e+00] + [-3.42117518e+00 -2.93178016e+00 -6.79049707e+00] + [-3.88572245e+00 -9.67789661e-02 -3.48044255e+00] + [-6.87995406e+00 -1.32491730e+00 -1.25451756e+00] + [-4.81551374e+00 -4.81827587e+00 -5.84400959e+00] + ... + +.. note:: + + User are allow to import coordinates from a file as well. Instead of ``mc.generate_initial_state(method = 'random', + num_particles = num_particles, box_length = box_length)``, use + ``mc.generate_initial_state(method = 'file', box_length = box_length)``. + +calculate energy in the system +++++++++++++++++++++++++++++++ + +In order to calculate the energy in the system, we need to initialize our box into unit box with ``wrap()`` and ``minimum_image_distance()``. + +.. code-block:: python + + box = mc.Box(coordinates = coordinates, box_length = box_length) + print(box.coordinates) + +add this into mc_lj.py, run it: + +.. code-block:: bash + + ~/my_project$ python mc_lj.py + [[-6.46469186e+00 -2.36139335e+00 -1.76851454e+00] + [-5.01314769e+00 -6.69468970e+00 -3.73106460e+00] + [-9.30764198e+00 -6.34829739e+00 -4.30931901e+00] + [-3.42117518e+00 -2.93178016e+00 -6.79049707e+00] + [-3.88572245e+00 -9.67789661e-02 -3.48044255e+00] + [-6.87995406e+00 -1.32491730e+00 -1.25451756e+00] + [-4.81551374e+00 -4.81827587e+00 -5.84400959e+00] + ... + +it will update our coordinates into the box. + +calculate total pair energy +--------------------------- + +.. code-block:: python + + mcs = mc.MCState(box1 = box, cutoff = 3.0) + total_pair_energy = mcs.calculate_total_energy() + print("total pair energy of the system is",total_pair_energy) + +The output is: + +.. code-block:: bash + + ~/my_project$ python mc_lj.py + total pair energy of the system is 18677707323853.145 + + +calculate tail correction +------------------------- + +.. code-block:: python + + tail_correction = mcs.calculate_tail_correction() + print("tail correction of the system is", tail_correction) + +The output is: + +.. code-block:: bash + + ~/my_project$ python mc_lj.py + tail correction of the system is -3.101388808502446 + + +calculate unit energy +--------------------- + +.. code-block:: python + + unit_energy = mcs.calculate_unit_energy() + print("unit energy of the system is",unit_energy) + +The output is: + +.. code-block:: bash + + ~/my_project$ python mc_lj.py + unit energy of the system is 186777073238.50043 + + +get particle energy +------------------- + +For example, the particle energy of the first particle can be obtained by ``mcs.get_particle_energy(0)`` where the **index 0** means the first particle in the system. + +.. code-block:: python + + particle_energy = mcs.get_particle_energy(0) + print("particle energy of the first particle is",particle_energy) + +The output is: + +.. code-block:: bash + + ~/my_project$ python mc_lj.py + particle energy of the first particle is 12.663401162199152 + + diff --git a/mc_lj.py b/mc_lj.py new file mode 100644 index 0000000..a8fc247 --- /dev/null +++ b/mc_lj.py @@ -0,0 +1,17 @@ +import mc_lj_potential as mc +import numpy as np +np.random.seed(123) +num_particles = 100 +box_length = 10.0 +coordinates = mc.generate_initial_state(method = 'random', num_particles = num_particles, box_length = box_length) +#print(coordinates) +box = mc.Box(coordinates = coordinates, box_length = box_length) +#print(box.coordinates) +mcs = mc.MCState(box1 = box, cutoff = 3.0) +total_pair_energy = mcs.calculate_total_pair_energy() +#print(total_pair_energy) +#print(mcs.calculate_tail_correction()) +#print(mcs.calculate_unit_energy()) +#print(mcs.get_particle_energy(0)) + + diff --git a/mc_lj_potential/mc_lj_potential.py b/mc_lj_potential/mc_lj_potential.py index c00061c..8cc56db 100644 --- a/mc_lj_potential/mc_lj_potential.py +++ b/mc_lj_potential/mc_lj_potential.py @@ -9,9 +9,15 @@ import numpy as np class Box: + + def __init__(self, box_length, coordinates = None): + self.box_length = box_length + self.coordinates = coordinates + def __init__(self, box_length, coordinates=None): self.box_length=box_length self.coordinates=coordinates + def wrap(self, coordinates,box_length): """ This is for wraping all particles in the box, updating the coordinates. @@ -192,10 +198,8 @@ def lennard_jones_potential(self, rij2): def generate_initial_state(method = 'random', file_name = None, num_particles = None, box_length = None): """ Generates initial state of the system. -​ - Generates the initial coordinates of all the atoms in the simulation box. If the method is random, the atoms are assigned a random set of coordinates. - If method is File, coordinates are loaded from a file. -​ + Generates the initial coordinates of all the atoms in the simulation box. If the method is random, the atoms are assigned a random set of coordinates. + If method is File, coordinates are loaded from a file. Parameters ---------- method : string. Either 'random' or 'File'. @@ -229,12 +233,10 @@ def accept_or_reject(delta_e, beta): Energy difference between initial and updated state of the system. beta : float Inverse reduced temperature, a general constant in canonical ensemble. -​ Returns ------- accept : boolean If true, trial move is accepted, else it is rejected. -​ """ if delta_e < 0.0: accept = True diff --git a/mc_lj_potential/tests/test_mc_lj_potential.py b/mc_lj_potential/tests/test_mc_lj_potential.py index b8fb45a..42899cc 100644 --- a/mc_lj_potential/tests/test_mc_lj_potential.py +++ b/mc_lj_potential/tests/test_mc_lj_potential.py @@ -10,6 +10,22 @@ import os import math +def test_num_particles(): + """ + Test if the property of num_particles is true. + """ + + coordinates = mc_lj_potential.generate_initial_state(method = 'random', num_particles = 100, box_length = 10.0 ) + mcs = mc_lj_potential.Box(coordinates = coordinates, box_length = 10.0) + + assert mcs.num_particles == 100 + +def test_volume(): + coordinates = mc_lj_potential.generate_initial_state(method = 'random', num_particles = 100, box_length = 5.0 ) + mcs = mc_lj_potential.Box(coordinates = coordinates, box_length = 5.0) + + assert mcs.volume == 125 + def test_mc_lj_potential_imported(): """ Sample test, will always pass so long as import statement worked. @@ -129,12 +145,25 @@ def test_accpet_or_reject_false(): np.random.seed(10) expected_vaule2 = False calculated_value2 = mc_lj_potential.accept_or_reject(6.0, 0.10) - print(calculated_value2) try: assert expected_vaule2 == calculated_value2 finally: np.random.seed() + +def test_accpet_or_reject_true_ran(): + """ + Test the accept_or_reject function when energy increase but it is still accepted. + """ + np.random.seed(354) + expected_vaule3 = True + calculated_value3 = mc_lj_potential.accept_or_reject(0.1, 0.10) + try: + assert expected_vaule3 == calculated_value3 + finally: + np.random.seed() + + def test_adjust_displacement_large(): """ Test the accept_or_reject function when the movement is too large that the max_displacement should be changed into a smaller value. diff --git a/tutorial.rst b/tutorial.rst new file mode 100644 index 0000000..e69de29