Skip to content

Commit

Permalink
Merge pull request #730 from chrisiacovella/master
Browse files Browse the repository at this point in the history
updated docs to reflect refactoring and remove use of depricated func…
  • Loading branch information
daico007 committed May 21, 2020
2 parents 60711ff + 04e6178 commit 4b60ced
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 62 deletions.
12 changes: 6 additions & 6 deletions docs/tutorials/ethane.mol2
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ NO_CHARGES
7 H -0.3570 0.7690 0.6530 H 1 RES
8 H -0.3570 0.1810 -0.9930 H 1 RES
@<TRIPOS>BOND
1 6 5 1
2 8 5 1
3 3 1 1
4 1 2 1
1 8 5 1
2 1 2 1
3 6 5 1
4 4 1 1
5 7 5 1
6 1 5 1
7 4 1 1
6 5 1 1
7 3 1 1
@<TRIPOS>SUBSTRUCTURE
1 RES 1 RESIDUE 0 **** ROOT 0
2 changes: 1 addition & 1 deletion docs/tutorials/tutorial_methane.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.9"
"version": "3.6.7"
},
"widgets": {
"state": {
Expand Down
37 changes: 31 additions & 6 deletions docs/tutorials/tutorial_monolayer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"source": [
"import mbuild as mb\n",
"\n",
"from mbuild.examples import Alkane\n",
"from mbuild.lib.recipes import Alkane\n",
"from mbuild.lib.moieties import Silane\n",
"\n",
"\n",
Expand Down Expand Up @@ -116,10 +116,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Also note the `backfill` optional argument which allows you to place a different compound on any unused ports. In this case we want to backfill with hydrogen atoms on every port without a chain.\n",
"\n",
"\n",
"And that's it! Check out `examples.alkane_monolayer` for the fully wrapped class."
"Also note the `backfill` optional argument which allows you to place a different compound on any unused ports. In this case we want to backfill with hydrogen atoms on every port without a chain."
]
},
{
Expand All @@ -141,6 +138,34 @@
"# Save as .mol2 file\n",
"monolayer.save('monolayer.mol2', overwrite=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"`lib.recipes.monolayer.py` wraps many these functions into a simple, general class for generating the monolayers, as shown below:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from mbuild.lib.recipes import Monolayer\n",
"\n",
"monolayer = Monolayer(fractions=[1.0], chains=alkylsilane, backfill=hydrogen, \n",
" pattern=mb.Grid2DPattern(n=8, m=8), \n",
" surface=surface, tile_x=2, tile_y=1)\n",
"monolayer.visualize()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -159,7 +184,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.9"
"version": "3.6.7"
}
},
"nbformat": 4,
Expand Down
86 changes: 60 additions & 26 deletions docs/tutorials/tutorial_polymers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,24 @@
"class CH2(mb.Compound):\n",
" def __init__(self):\n",
" super(CH2, self).__init__()\n",
" # Add carbon \n",
" self.add(mb.Particle(name='C', pos=[0,0,0]), label='C[$]')\n",
" \n",
" # Add hydrogens \n",
" self.add(mb.Particle(name='H', pos=[-0.109, 0, 0.0]), label='HC[$]') \n",
" self.add(mb.Particle(name='H', pos=[0.109, 0, 0.0]), label='HC[$]')\n",
" \n",
" # Add bonds between the atoms\n",
" self.add_bond((self['C'][0], self['HC'][0]))\n",
" self.add_bond((self['C'][0], self['HC'][1]))\n",
" \n",
" # Add ports anchored to the carbon\n",
" self.add(mb.Port(anchor=self[0]), label='up')\n",
" self.add(mb.Port(anchor=self[0]), label='down')\n",
" \n",
" # Move the ports approximately half a C-C bond length away from the carbon\n",
" mb.translate(self['up'], [0, -0.154/2, 0]) \n",
" mb.translate(self['down'], [0, 0.154/2, 0]) \n",
" self['up'].translate([0, -0.154/2, 0]) \n",
" self['down'].translate([0, 0.154/2, 0]) \n",
"\n",
"monomer = CH2()\n",
"monomer.visualize(show_ports=True)"
Expand All @@ -78,19 +83,32 @@
"class CH2(mb.Compound):\n",
" def __init__(self):\n",
" super(CH2, self).__init__()\n",
" # Add carbon\n",
" self.add(mb.Particle(name='C', pos=[0,0,0]), label='C[$]')\n",
" \n",
" # Add hydrogens \n",
" self.add(mb.Particle(name='H', pos=[-0.109, 0, 0.0]), label='HC[$]') \n",
" self.add(mb.Particle(name='H', pos=[0.109, 0, 0.0]), label='HC[$]')\n",
" \n",
" # Rotate the hydrogens\n",
" theta = 0.5 * (180 - 109.5) * np.pi / 180\n",
" mb.rotate(self['HC'][0], theta, around=[0, 1, 0])\n",
" mb.rotate(self['HC'][1], -theta, around=[0, 1, 0])\n",
" #mb.rotate(self['HC'][0], theta, around=[0, 1, 0])\n",
" #mb.rotate(self['HC'][1], -theta, around=[0, 1, 0])\n",
" self['HC'][0].rotate( theta, around=[0, 1, 0])\n",
" self['HC'][1].rotate(-theta, around=[0, 1, 0])\n",
" \n",
" # Add bonds between the atoms\n",
" self.add_bond((self['C'][0], self['HC'][0]))\n",
" self.add_bond((self['C'][0], self['HC'][1]))\n",
" \n",
" # Add the ports and appropriately rotate them\n",
" self.add(mb.Port(anchor=self[0]), label='up')\n",
" mb.translate(self['up'], [0, -0.154/2, 0]) \n",
" mb.rotate(self['up'], theta, around=[1, 0, 0])\n",
" self['up'].translate([0, -0.154/2, 0]) \n",
" self['up'].rotate(theta, around=[1, 0, 0])\n",
" \n",
" self.add(mb.Port(anchor=self[0]), label='down')\n",
" mb.translate(self['down'], [0, 0.154/2, 0]) \n",
" mb.rotate(self['down'], -theta, around=[1, 0, 0]) \n",
" self['down'].translate([0, 0.154/2, 0]) \n",
" self['down'].rotate(-theta, around=[1, 0, 0]) \n",
"\n",
"monomer = CH2()\n",
"monomer.visualize(show_ports=True)"
Expand Down Expand Up @@ -137,7 +155,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Visualization of this structure demonstrates a problem; the polymer curls up on itself. This is a result of the fact that ports not only define the location in space, but also an orientation. This can be trivially fixed, by first rotating the port 180&deg; around the y-axis. \n",
"Visualization of this structure demonstrates a problem; the polymer curls up on itself. This is a result of the fact that ports not only define the location in space, but also an orientation. This can be trivially fixed, by rotating the down port 180&deg; around the y-axis. \n",
"\n",
"We can also add a variable ```chain_length``` both to the for loop and ```init``` that will allow the length of the polymer to be adjusted when the class is instantiated. "
]
Expand All @@ -154,20 +172,29 @@
"class CH2(mb.Compound):\n",
" def __init__(self):\n",
" super(CH2, self).__init__()\n",
" # Add carbons and hydrogens\n",
" self.add(mb.Particle(name='C', pos=[0,0,0]), label='C[$]')\n",
" self.add(mb.Particle(name='H', pos=[-0.109, 0, 0.0]), label='HC[$]') \n",
" self.add(mb.Particle(name='H', pos=[0.109, 0, 0.0]), label='HC[$]')\n",
" \n",
" # rotate hydrogens\n",
" theta = 0.5 * (180 - 109.5) * np.pi / 180\n",
" mb.rotate(self['HC'][0], theta, around=[0, 1, 0])\n",
" mb.rotate(self['HC'][1], -theta, around=[0, 1, 0])\n",
" self['HC'][0].rotate(theta, around=[0, 1, 0])\n",
" self['HC'][1].rotate(-theta, around=[0, 1, 0])\n",
" \n",
" # Add bonds between the atoms\n",
" self.add_bond((self['C'][0], self['HC'][0]))\n",
" self.add_bond((self['C'][0], self['HC'][1]))\n",
" \n",
" # Add ports\n",
" self.add(mb.Port(anchor=self[0]), label='up')\n",
" mb.translate(self['up'], [0, -0.154/2, 0]) \n",
" mb.rotate(self['up'], theta, around=[1, 0, 0])\n",
" self['up'].translate([0, -0.154/2, 0]) \n",
" self['up'].rotate(theta, around=[1, 0, 0])\n",
" \n",
" self.add(mb.Port(anchor=self[0]), label='down')\n",
" mb.translate(self['down'], [0, 0.154/2, 0])\n",
" mb.rotate(self['down'], np.pi, [0, 1, 0])\n",
" mb.rotate(self['down'], -theta, around=[1, 0, 0]) \n",
" self['down'].translate([0, 0.154/2, 0])\n",
" self['down'].rotate(np.pi, [0, 1, 0])\n",
" self['down'].rotate(-theta, around=[1, 0, 0]) \n",
"\n",
"\n",
"class AlkanePolymer(mb.Compound):\n",
Expand Down Expand Up @@ -248,7 +275,7 @@
"\n",
"# the pattern we generate puts points in the xy-plane, so we'll rotate the polymer\n",
"# so that it is oriented normal to the xy-plane\n",
"mb.rotate(polymer, np.pi/2, [1, 0, 0])\n",
"polymer.rotate(np.pi/2, [1, 0, 0])\n",
"\n",
"# define a compound to hold all the polymers\n",
"system = mb.Compound()\n",
Expand All @@ -262,7 +289,7 @@
"# now clone the polymer and move it to the points in the pattern\n",
"for pos in pattern_disk:\n",
" current_polymer = mb.clone(polymer)\n",
" mb.translate(current_polymer, pos)\n",
" current_polymer.translate(pos)\n",
" system.add(current_polymer)\n",
" \n",
"system.visualize()"
Expand All @@ -287,16 +314,16 @@
"\n",
"polymer = mb.lib.recipes.Polymer(CH2(), 10, port_labels=('up', 'down'))\n",
"system = mb.Compound()\n",
"mb.rotate(polymer, np.pi/2, [1, 0, 0])\n",
"polymer.rotate(np.pi/2, [1, 0, 0])\n",
"\n",
"pattern_disk = mb.Grid3DPattern(5, 5, 5)\n",
"pattern_disk.scale(8.0)\n",
" \n",
"for pos in pattern_disk:\n",
" current_polymer = mb.clone(polymer)\n",
" for around in [(1, 0, 0), (0, 1, 0), (0, 0, 1)]: # rotate around x, y, and z\n",
" mb.rotate(current_polymer, random.uniform(0, np.pi), around)\n",
" mb.translate(current_polymer, pos)\n",
" current_polymer.rotate(random.uniform(0, np.pi), around)\n",
" current_polymer.translate(pos)\n",
" system.add(current_polymer)\n",
"\n",
"system.visualize()"
Expand Down Expand Up @@ -353,13 +380,13 @@
" super(AlkanePolymer, self).__init__()\n",
" monomer_proto = CH2()\n",
" last_monomer = CH2()\n",
" mb.rotate(last_monomer['down'], random.uniform(-delta,delta), [1, 0, 0])\n",
" mb.rotate(last_monomer['down'], random.uniform(-delta,delta), [0, 1, 0])\n",
" last_monomer['down'].rotate(random.uniform(-delta,delta), [1, 0, 0])\n",
" last_monomer['down'].rotate(random.uniform(-delta,delta), [0, 1, 0])\n",
" self.add(last_monomer)\n",
" for i in range(chain_length-1):\n",
" current_monomer = mb.clone(monomer_proto)\n",
" mb.rotate(current_monomer['down'], random.uniform(-delta,delta), [1, 0, 0])\n",
" mb.rotate(current_monomer['down'], random.uniform(-delta,delta), [0, 1, 0])\n",
" current_monomer['down'].rotate(random.uniform(-delta,delta), [1, 0, 0])\n",
" current_monomer['down'].rotate(random.uniform(-delta,delta), [0, 1, 0])\n",
" mb.force_overlap(move_this=current_monomer, \n",
" from_positions=current_monomer['up'], \n",
" to_positions=last_monomer['down'])\n",
Expand All @@ -369,6 +396,13 @@
"polymer = AlkanePolymer(chain_length = 200, delta=0.4)\n",
"polymer.visualize()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -387,7 +421,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.9"
"version": "3.6.7"
},
"widgets": {
"state": {
Expand Down

0 comments on commit 4b60ced

Please sign in to comment.