From dee97a38c9a4c941d186299640b781371a6c7681 Mon Sep 17 00:00:00 2001 From: chrisjonesbsu Date: Tue, 3 Oct 2023 12:45:20 -0600 Subject: [PATCH 1/5] add graphene surface to library --- hoomd_organics/library/__init__.py | 1 + hoomd_organics/library/surfaces.py | 44 ++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 hoomd_organics/library/surfaces.py diff --git a/hoomd_organics/library/__init__.py b/hoomd_organics/library/__init__.py index 4f730899..146c9f06 100644 --- a/hoomd_organics/library/__init__.py +++ b/hoomd_organics/library/__init__.py @@ -20,3 +20,4 @@ PolyEthylene, ) from .simulations.tensile import Tensile +from .surfaces import Graphene diff --git a/hoomd_organics/library/surfaces.py b/hoomd_organics/library/surfaces.py new file mode 100644 index 00000000..6b201f08 --- /dev/null +++ b/hoomd_organics/library/surfaces.py @@ -0,0 +1,44 @@ +"""Recipes to generate surfaces using mBuild.""" + +from mbuild.compound import Compound +from mbuild.lattice import Lattice + + +class Graphene(Compound): + """Creates a rectangular graphene layer or multiple layers. + + Parameters + ---------- + x_repeat : int, required + Number of times to repeat graphene lattice in the x-direciton + y_repeat: int, required + Number of times to repeat graphene lattice in the y-direciton + n_layers: int, optional, default 1 + Number of times to repeat the complete layer in the normal direction + periodicity : tuple of bools, length=3, optional, default=None + Whether the Compound is periodic in the x, y, and z directions. + If None is provided, the periodicity is set to (False, False, False) + which is non-periodic in all directions. + + Notes + ----- + To create bonds along periodic boundaries of the layers in the x and y + directions, set periodicity to (True, True, False) + + """ + + def __init__(self, x_repeat, y_repeat, n_layers, periodicity=None): + super(Graphene, self).__init__(periodicity=periodicity) + spacings = [0.425, 0.246, 0.35] + points = [[1 / 6, 0, 0], [1 / 2, 0, 0], [0, 0.5, 0], [2 / 3, 1 / 2, 0]] + lattice = Lattice( + lattice_spacing=spacings, + angles=[90, 90, 90], + lattice_points={"A": points}, + ) + carbon = Compound(name="C") + layers = lattice.populate( + compound_dict={"A": carbon}, x=x_repeat, y=y_repeat, z=n_layers + ) + self.add(layers) + self.freud_generate_bonds("C", "C", dmin=0.14, dmax=0.145) From 6b4e33b15f4e0373856968502952c77fe1533934 Mon Sep 17 00:00:00 2001 From: chrisjonesbsu Date: Tue, 3 Oct 2023 12:47:52 -0600 Subject: [PATCH 2/5] add unit tests for graphene surface --- hoomd_organics/tests/library/test_surfaces.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 hoomd_organics/tests/library/test_surfaces.py diff --git a/hoomd_organics/tests/library/test_surfaces.py b/hoomd_organics/tests/library/test_surfaces.py new file mode 100644 index 00000000..aed4a76d --- /dev/null +++ b/hoomd_organics/tests/library/test_surfaces.py @@ -0,0 +1,21 @@ +from hoomd_organics.library import Graphene + + +class TestSurfaces: + def test_create_graphene_surface(self): + surface = Graphene( + x_repeat=2, + y_repeat=2, + n_layers=3, + periodicity=(False, False, False), + ) + assert surface.n_particles == 4 * 2 * 2 * 3 + assert surface.n_bonds == 54 + + def test_graphene_with_periodicity(self): + surface = Graphene( + x_repeat=2, y_repeat=2, n_layers=3, periodicity=(True, True, False) + ) + assert surface.n_particles == 4 * 2 * 2 * 3 + assert surface.periodicity == (True, True, False) + assert surface.n_bonds == 72 From 4a4e93a4b421e3e0768981f16cf7c8f8a52ccec4 Mon Sep 17 00:00:00 2001 From: chrisjonesbsu Date: Tue, 3 Oct 2023 12:50:09 -0600 Subject: [PATCH 3/5] change periodicity default --- hoomd_organics/library/surfaces.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hoomd_organics/library/surfaces.py b/hoomd_organics/library/surfaces.py index 6b201f08..e0053fd4 100644 --- a/hoomd_organics/library/surfaces.py +++ b/hoomd_organics/library/surfaces.py @@ -15,7 +15,7 @@ class Graphene(Compound): Number of times to repeat graphene lattice in the y-direciton n_layers: int, optional, default 1 Number of times to repeat the complete layer in the normal direction - periodicity : tuple of bools, length=3, optional, default=None + periodicity : tuple of bools, length=3, optional, default=(True, True, False) # noqa: E501 Whether the Compound is periodic in the x, y, and z directions. If None is provided, the periodicity is set to (False, False, False) which is non-periodic in all directions. @@ -27,7 +27,9 @@ class Graphene(Compound): """ - def __init__(self, x_repeat, y_repeat, n_layers, periodicity=None): + def __init__( + self, x_repeat, y_repeat, n_layers, periodicity=(True, True, False) + ): super(Graphene, self).__init__(periodicity=periodicity) spacings = [0.425, 0.246, 0.35] points = [[1 / 6, 0, 0], [1 / 2, 0, 0], [0, 0.5, 0], [2 / 3, 1 / 2, 0]] From e87f075e9f1d7c207b37415e9920b504642807c8 Mon Sep 17 00:00:00 2001 From: chrisjonesbsu Date: Tue, 3 Oct 2023 13:07:47 -0600 Subject: [PATCH 4/5] doc string changes --- hoomd_organics/library/surfaces.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hoomd_organics/library/surfaces.py b/hoomd_organics/library/surfaces.py index e0053fd4..2b433f64 100644 --- a/hoomd_organics/library/surfaces.py +++ b/hoomd_organics/library/surfaces.py @@ -17,7 +17,7 @@ class Graphene(Compound): Number of times to repeat the complete layer in the normal direction periodicity : tuple of bools, length=3, optional, default=(True, True, False) # noqa: E501 Whether the Compound is periodic in the x, y, and z directions. - If None is provided, the periodicity is set to (False, False, False) + If None is provided, the periodicity is set to `(False, False, False)` which is non-periodic in all directions. Notes From d0af69f1b7c16b0429e4a16701cb8e2281fb3453 Mon Sep 17 00:00:00 2001 From: chrisjonesbsu Date: Tue, 3 Oct 2023 13:13:36 -0600 Subject: [PATCH 5/5] fix doc strings --- hoomd_organics/library/surfaces.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hoomd_organics/library/surfaces.py b/hoomd_organics/library/surfaces.py index 2b433f64..302b3365 100644 --- a/hoomd_organics/library/surfaces.py +++ b/hoomd_organics/library/surfaces.py @@ -5,16 +5,16 @@ class Graphene(Compound): - """Creates a rectangular graphene layer or multiple layers. + """Create a rectangular graphene layer or multiple layers. Parameters ---------- x_repeat : int, required - Number of times to repeat graphene lattice in the x-direciton + Number of times to repeat graphene lattice in the x-direciton. y_repeat: int, required - Number of times to repeat graphene lattice in the y-direciton + Number of times to repeat graphene lattice in the y-direciton. n_layers: int, optional, default 1 - Number of times to repeat the complete layer in the normal direction + Number of times to repeat the complete layer in the normal direction. periodicity : tuple of bools, length=3, optional, default=(True, True, False) # noqa: E501 Whether the Compound is periodic in the x, y, and z directions. If None is provided, the periodicity is set to `(False, False, False)` @@ -23,7 +23,7 @@ class Graphene(Compound): Notes ----- To create bonds along periodic boundaries of the layers in the x and y - directions, set periodicity to (True, True, False) + directions, set `periodicity = (True, True, False)` """