Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -178,74 +178,72 @@
},
{
"cell_type": "markdown",
"id": "15058f13",
"id": "599d90ef",
"metadata": {},
"source": [
"Now we create a mapping from the atom type names to consecutive integer IDs that LAMMPS requires. We use a `set` to get the unique atom types from our packed system and assign each a numeric identifier."
"## Creating the snapshot\n",
"\n",
"Now we create a `Snapshot` to hold all our molecular data. We calculate the total number of atoms and define a simulation box that contains our system. We use the same box dimensions that were specified in our PACKMOL input file: a cubic box extending from 0 to 25 Å in each direction."
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "25c38ff0",
"id": "551604e8",
"metadata": {},
"outputs": [],
"source": [
"unique_types = set(types)\n",
"combined_type_map = {type: i + 1 for i, type in enumerate(unique_types)}"
"N_total = N_water * atoms_per_water + N_ethanol * atoms_per_ethanol\n",
"box = lammpsio.Box([0, 0, 0], [L_box, L_box, L_box])\n",
"\n",
"snap = lammpsio.Snapshot(N_total, box, step=0)"
]
},
{
"cell_type": "markdown",
"id": "599d90ef",
"id": "2331e903",
"metadata": {},
"source": [
"## Creating the snapshot\n",
"## Assigning atomic properties\n",
"\n",
"Now we create a `Snapshot` to hold all our molecular data. We calculate the total number of atoms and define a simulation box that contains our system. We use the same box dimensions that were specified in our PACKMOL input file: a cubic box extending from -12.5 to 12.5 Å in each direction."
"Now we assign positions, masses, and type IDs to each atom. The packed coordinates are assigned to each atom directly from the PACKMOL output."
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "551604e8",
"id": "d66437e5",
"metadata": {},
"outputs": [],
"source": [
"N_total = N_water * atoms_per_water + N_ethanol * atoms_per_ethanol\n",
"box = lammpsio.Box([0, 0, 0], [L_box, L_box, L_box])\n",
"\n",
"snap = lammpsio.Snapshot(N_total, box, step=0)"
"snap.position = positions"
]
},
{
"cell_type": "markdown",
"id": "2331e903",
"id": "15058f13",
"metadata": {},
"source": [
"## Assigning atomic properties\n",
"\n",
"Now we assign positions, masses, and type IDs to each atom. The packed coordinates are assigned to each atom directly from the PACKMOL output."
" We use a `set` to get the unique atom types from our packed system and assign each a numeric identifier. Then, we create a `LabelMap` to link integer type IDs to their corresponding atom type, which could be useful for later force field assignment."
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "d66437e5",
"id": "25c38ff0",
"metadata": {},
"outputs": [],
"source": [
"snap.position = positions"
"unique_types = set(types)\n",
"snap.type_label = lammpsio.LabelMap({idx+1: atom_type for idx, atom_type in enumerate(unique_types)})"
]
},
{
"cell_type": "markdown",
"id": "2ecfa03e",
"metadata": {},
"source": [
"We extract the atomic type and mass information from each molecule's JSON and replicate them by the number of each molecule. We concatenate these together, remembering that water's coordinates were generated first by PACKMOL, and assign them to the `Snapshot` object.\n",
"\n",
"Finally, we create a `LabelMap` to link integer type IDs to their corresponding atom type, which could be useful for later force field assignment."
"We use the `LabelMap` to convert the atom types and assign integer type IDs. We extract the atomic mass information from each molecule's JSON and replicate them by the number of each molecule. We concatenate these together, remembering that water's coordinates were generated first by PACKMOL, and assign them to the `Snapshot` object."
]
},
{
Expand All @@ -256,8 +254,7 @@
"outputs": [],
"source": [
"# assign type IDs\n",
"snap.typeid = [combined_type_map[t] for t in types]\n",
"snap.type_label = lammpsio.LabelMap({id: type for type, id in combined_type_map.items()})\n",
"snap.typeid = [snap.type_label.inverse[t] for t in types]\n",
"\n",
"# assign masses\n",
"water_mass = [mass for _, mass in water_data[\"masses\"][\"data\"]]\n",
Expand Down Expand Up @@ -323,7 +320,7 @@
"source": [
"## Creating bonds\n",
"\n",
"We extract the bond topology from the molecular data files we loaded earlier. Each molecule type has its own set of bonds defined in the JSON files. We start by reading the bond information from both molecule types and creating a mapping from the original bond type names to consecutive integer bond IDs that LAMMPS requires."
"We extract the bond topology from the molecular data files we loaded earlier. Each molecule type has its own set of bonds defined in the JSON files. We start by reading the bond information from both molecule types."
]
},
{
Expand All @@ -342,7 +339,7 @@
"id": "71b84028",
"metadata": {},
"source": [
"Now we calculate the total number of bonds, use our helper function to get the bond topology for all molecules, and create a mapping from bond type names to integer IDs that LAMMPS requires."
"Now we calculate the total number of bonds, use our helper function to get the bond topology for all molecules, and get the unique bonds in the system."
]
},
{
Expand All @@ -362,17 +359,16 @@
" atoms_per_molecule=[atoms_per_water, atoms_per_ethanol],\n",
")\n",
"\n",
"# create mapping from bond type names to integer IDs\n",
"unique_bonds = set(bond_types)\n",
"bond_type_map = {bond_type:idx+1 for idx, bond_type in enumerate(unique_bonds)}"
"# get unique bond types\n",
"unique_bonds = set(bond_types)"
]
},
{
"cell_type": "markdown",
"id": "e6ab5f74",
"metadata": {},
"source": [
"Finally, we create and assign the `Bonds` object with all the bond connectivity, numeric type-id information for our system and `LabelMap`."
"Finally, we create and assign the `Bonds` object with all the bond connectivity, `LabelMap`, and integer type-id information for our system."
]
},
{
Expand All @@ -385,8 +381,8 @@
"\n",
"snap.bonds = lammpsio.Bonds(N=N_bonds, num_types=len(unique_bonds))\n",
"snap.bonds.members = bond_members\n",
"snap.bonds.typeid = [bond_type_map[bond_type] for bond_type in bond_types]\n",
"snap.bonds.type_label = lammpsio.LabelMap({id: bond_type for bond_type, id in bond_type_map.items()})"
"snap.bonds.type_label = lammpsio.LabelMap({idx+1:bond_type for idx, bond_type in enumerate(unique_bonds)})\n",
"snap.bonds.typeid = [snap.bonds.type_label.inverse[bond_type] for bond_type in bond_types]"
]
},
{
Expand All @@ -396,7 +392,7 @@
"source": [
"## Creating angles\n",
"\n",
"We follow the same approach for angles as we did for bonds: extract the angle topology from the molecule JSON files, create a mapping from the original angle type names to angle IDs, replicate the per-molecule angles to all molecules in the system, and finally create the `Angles` object to store all the angle information for the system."
"We follow the same approach for angles as we did for bonds: extract the angle topology from the molecule JSON files, replicate the per-molecule angles to all molecules in the system, and finally create the `Angles` object to store all the angle information and the `LabelMap` for the system."
]
},
{
Expand All @@ -420,15 +416,14 @@
" atoms_per_molecule=[atoms_per_water, atoms_per_ethanol],\n",
")\n",
"\n",
"# create mapping from angle type names to integer IDs\n",
"# get unique angle types\n",
"unique_angles = set(angle_types)\n",
"angle_type_map = {angle_type:idx+1 for idx, angle_type in enumerate(unique_angles)}\n",
"\n",
"# create and assign the Angles object\n",
"snap.angles = lammpsio.Angles(N=N_angles, num_types=len(unique_angles))\n",
"snap.angles.members = angle_members\n",
"snap.angles.typeid = [angle_type_map[angle_type] for angle_type in angle_types]\n",
"snap.angles.type_label = lammpsio.LabelMap({id: angle_type for angle_type, id in angle_type_map.items()})"
"snap.angles.type_label = lammpsio.LabelMap({idx+1:angle_type for idx, angle_type in enumerate(unique_angles)})\n",
"snap.angles.typeid = [snap.angles.type_label.inverse[angle_type] for angle_type in angle_types]"
]
},
{
Expand Down Expand Up @@ -463,15 +458,14 @@
" atoms_per_molecule=[atoms_per_ethanol],\n",
")\n",
"\n",
"# create mapping from dihedral type names to integer IDs\n",
"# get unique dihedral types\n",
"unique_dihedrals = set(dihedral_types)\n",
"dihedral_type_map = {dihedral_type:idx+1 for idx, dihedral_type in enumerate(unique_dihedrals)}\n",
"\n",
"# create and assign the Dihedrals object\n",
"snap.dihedrals = lammpsio.Dihedrals(N=N_dihedrals, num_types=len(unique_dihedrals))\n",
"snap.dihedrals.members = dihedral_members\n",
"snap.dihedrals.typeid = [dihedral_type_map[dihedral_type] for dihedral_type in dihedral_types]\n",
"snap.dihedrals.type_label = lammpsio.LabelMap({id: dihedral_type for dihedral_type, id in dihedral_type_map.items()})"
"snap.dihedrals.type_label = lammpsio.LabelMap({idx+1: dihedral_type for idx, dihedral_type in enumerate(unique_dihedrals)})\n",
"snap.dihedrals.typeid = [snap.dihedrals.type_label.inverse[dihedral_type] for dihedral_type in dihedral_types]"
]
},
{
Expand All @@ -493,7 +487,7 @@
{
"data": {
"text/plain": [
"<lammpsio.data.DataFile at 0x10c151bb0>"
"<lammpsio.data.DataFile at 0x105279730>"
]
},
"execution_count": 17,
Expand Down
Loading