Skip to content

Commit d80f38b

Browse files
Merge pull request #501 from justinGilmer/new_plugin
Add recipe/plugin architecture
2 parents b34aacf + fda50fb commit d80f38b

18 files changed

+89
-45
lines changed

mbuild/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from mbuild.pattern import *
66
from mbuild.packing import *
77
from mbuild.port import Port
8-
from mbuild.recipes import *
98
from mbuild.lattice import Lattice
10-
9+
from mbuild.recipes import recipes
1110
from mbuild.version import version

mbuild/examples/alkane/alkane.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from mbuild.lib.moieties import CH2
55
from mbuild.lib.moieties import CH3
6+
from mbuild.lib.recipes import Polymer
67

78

89
class Alkane(mb.Compound):
@@ -24,7 +25,7 @@ def __init__(self, n=3, cap_front=True, cap_end=True):
2425
n += 1
2526
if not cap_end:
2627
n += 1
27-
chain = mb.Polymer(CH2(), n=n-2, port_labels=('up', 'down'))
28+
chain = mb.recipes.Polymer(CH2(), n=n-2, port_labels=('up', 'down'))
2829
self.add(chain, 'chain')
2930

3031
if cap_front:
@@ -43,4 +44,4 @@ def __init__(self, n=3, cap_front=True, cap_end=True):
4344
# Hoist port label to Alkane level.
4445
self.add(chain['down'], 'down', containment=False)
4546

46-
# -- ==alkane== --
47+
# -- ==alkane== --

mbuild/examples/alkane_monolayer/alkane_monolayer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66

77
from mbuild.lib.surfaces import Betacristobalite
88
from mbuild.lib.atoms import H
9+
from mbuild.lib.recipes import Monolayer
910
from mbuild.examples.alkane_monolayer.alkylsilane import AlkylSilane
1011

1112

12-
class AlkaneMonolayer(mb.Monolayer):
13+
class AlkaneMonolayer(mb.recipes.Monolayer):
1314
"""An akylsilane monolayer on beta-cristobalite. """
1415

1516
def __init__(self, pattern, tile_x=1, tile_y=1, chain_length=10):
@@ -34,4 +35,4 @@ def __init__(self, pattern, tile_x=1, tile_y=1, chain_length=10):
3435
pattern=pattern, tile_x=tile_x,
3536
tile_y=tile_y)
3637

37-
# -- ==alkane_monolayer== --
38+
# -- ==alkane_monolayer== --

mbuild/examples/pmpc/brush.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from mbuild.lib.moieties import Silane
66
from mbuild.lib.moieties import CH3
7+
from mbuild.lib.recipes import Polymer
78
from mbuild.examples.pmpc.mpc import MPC
89
from mbuild.examples.pmpc.initiator import Initiator
910

@@ -16,7 +17,7 @@ def __init__(self, chain_length=4, alpha=pi/4):
1617
# Add parts
1718
self.add(Silane(), label='silane')
1819
self.add(Initiator(), label='initiator')
19-
self.add(mb.Polymer(MPC(alpha=alpha), n=chain_length,
20+
self.add(mb.recipes.Polymer(MPC(alpha=alpha), n=chain_length,
2021
port_labels=('up', 'down')), label='pmpc')
2122
self.add(CH3(), label='methyl')
2223

mbuild/examples/pmpc/pmpc_brush_layer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
from numpy import pi
88

99
import mbuild as mb
10-
1110
from mbuild.lib.atoms import H
1211
from mbuild.lib.surfaces import Betacristobalite
12+
from mbuild.lib.recipes import Monolayer
1313
from mbuild.examples.pmpc.brush import Brush
1414

1515

16-
class PMPCLayer(mb.Monolayer):
16+
class PMPCLayer(mb.recipes.Monolayer):
1717
"""Create a layer of grafted pMPC brushes on a beta-cristobalite surface."""
1818
def __init__(self, pattern, tile_x=1, tile_y=1, chain_length=4, alpha=pi / 4):
1919
surface = Betacristobalite()
@@ -23,4 +23,4 @@ def __init__(self, pattern, tile_x=1, tile_y=1, chain_length=4, alpha=pi / 4):
2323
pattern=pattern, tile_x=tile_x,
2424
tile_y=tile_y)
2525

26-
# -- ==pmpc_brush_layer== --
26+
# -- ==pmpc_brush_layer== --

mbuild/lib/recipes/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from mbuild.lib.recipes.polymer import Polymer
2+
from mbuild.lib.recipes.monolayer import Monolayer
3+
from mbuild.lib.recipes.tiled_compound import TiledCompound
4+
from mbuild.lib.recipes.silica_interface import SilicaInterface

mbuild/recipes/monolayer.py renamed to mbuild/lib/recipes/monolayer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import numpy as np
55

66
import mbuild as mb
7+
from mbuild.lib.recipes.tiled_compound import TiledCompound
78

89
__all__ = ['Monolayer']
910

@@ -37,15 +38,15 @@ def __init__(self, surface, chains, fractions=None, backfill=None, pattern=None,
3738
super(Monolayer, self).__init__()
3839

3940
# Replicate the surface.
40-
tiled_compound = mb.TiledCompound(surface, n_tiles=(tile_x, tile_y, 1))
41+
tiled_compound = mb.recipes.TiledCompound(surface, n_tiles=(tile_x, tile_y, 1))
4142
self.add(tiled_compound, label='tiled_surface')
4243

4344
if pattern is None: # Fill the surface.
4445
pattern = mb.Random2DPattern(len(tiled_compound.referenced_ports()))
4546

4647
if isinstance(chains, mb.Compound):
4748
chains = [chains]
48-
49+
4950
if fractions:
5051
fractions = list(fractions)
5152
if len(chains) != len(fractions):
File renamed without changes.

mbuild/recipes/silica_interface.py renamed to mbuild/lib/recipes/silica_interface.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import mbuild as mb
77
import numpy as np
8+
from mbuild.lib.recipes import TiledCompound
89

910

1011
class SilicaInterface(mb.Compound):
@@ -60,13 +61,13 @@ def _cleave_interface(self, bulk_silica, tile_x, tile_y, thickness):
6061
"""
6162
O_buffer = self._O_buffer
6263
tile_z = int(math.ceil((thickness + 2*O_buffer) / bulk_silica.periodicity[2]))
63-
bulk = mb.TiledCompound(bulk_silica, n_tiles=(tile_x, tile_y, tile_z))
64+
bulk = mb.recipes.TiledCompound(bulk_silica, n_tiles=(tile_x, tile_y, tile_z))
6465

6566
interface = mb.Compound(periodicity=(bulk.periodicity[0],
6667
bulk.periodicity[1],
6768
0.0))
6869
for i, particle in enumerate(bulk.particles()):
69-
if ((particle.name == 'Si' and O_buffer < particle.pos[2] < (thickness + O_buffer)) or
70+
if ((particle.name == 'Si' and O_buffer < particle.pos[2] < (thickness + O_buffer)) or
7071
(particle.name == 'O' and particle.pos[2] < (thickness + 2*O_buffer))):
7172
interface_particle = mb.Compound(name=particle.name, pos=particle.pos)
7273
interface.add(interface_particle, particle.name + "_{}".format(i))
@@ -153,5 +154,5 @@ def _adjust_stoichiometry(self):
153154

154155
if __name__ == "__main__":
155156
from mbuild.lib.bulk_materials import AmorphousSilica
156-
silica_interface = mb.SilicaInterface(bulk_silica=AmorphousSilica(), thickness=1.2)
157+
silica_interface = mb.recipes.SilicaInterface(bulk_silica=AmorphousSilica(), thickness=1.2)
157158
silica_interface.save('silica_interface.mol2', show_ports=True)

0 commit comments

Comments
 (0)