Skip to content

Commit 1b0812d

Browse files
committed
Merge branch 'fine-grain' of github.com:chrisjonesBSU/grits into fine-grain
2 parents 82bb2a5 + 02bc609 commit 1b0812d

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

grits/finegrain.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
import itertools as it
44
from collections import defaultdict
55

6-
from cmeutils.geometry import angle_between_vectors
7-
from mbuild import Compound, Particle, load
6+
import gsd.hoomd
87
import mbuild as mb
98
import numpy as np
10-
import gsd.hoomd
9+
from cmeutils.geometry import angle_between_vectors
10+
from mbuild import Compound, Particle, load
1111

1212
from grits.utils import align, get_hydrogen, get_index, reactant_dict
1313

14+
1415
def backmap_snapshot_to_compound(
1516
snapshot,
1617
bead_mapping=None,
@@ -20,7 +21,7 @@ def backmap_snapshot_to_compound(
2021
ref_distance=None,
2122
energy_minimize=False
2223
):
23-
#TODO
24+
# TODO
2425
# assert all 3 dicts have the same keys
2526
if (bead_mapping is None and bond_head_index is None and bond_tail_index is None) == (library_key is None):
2627
raise ValueError(
@@ -37,12 +38,11 @@ def backmap_snapshot_to_compound(
3738
box = cg_snap.configuration.box * ref_distance
3839
pos_adjust = np.array([box[0] / 2, box[1] / 2, box[2] / 2])
3940
mb_box = mb.box.Box.from_lengths_angles(
40-
lengths=[box[0], box[1], box[2]],
41-
angles=[90.0, 90.0, 90.0]
41+
lengths=[box[0], box[1], box[2]], angles=[90.0, 90.0, 90.0]
4242
)
4343
fg_compound.box = mb_box
4444
# Create atomistic compounds, remove hydrogens in the way of bonds
45-
compounds = dict()
45+
compounds = dict()
4646
anchor_dict = dict()
4747
for mapping in bead_mapping:
4848
comp = mb.load(bead_mapping[mapping], smiles=True)
@@ -68,9 +68,9 @@ def backmap_snapshot_to_compound(
6868
for i in [bond_tail_index[mapping][0], bond_head_index[mapping][0]]:
6969
for j, particle in enumerate(comp.particles()):
7070
if j == i:
71-
remove_atoms.append(particle)
71+
remove_atoms.append(particle)
7272
anchor = [p for p in particle.direct_bonds()][0]
73-
anchor_particles.append(anchor)
73+
anchor_particles.append(anchor)
7474
for particle in remove_atoms:
7575
comp.remove(particle)
7676
# List of length 2 [tail particle index, head particle index]
@@ -88,46 +88,48 @@ def backmap_snapshot_to_compound(
8888
mb_compounds = []
8989
for group in cg_snap.bonds.group:
9090
cg_bond_vec = (
91-
cg_snap.particles.position[group[1]] -
92-
cg_snap.particles.position[group[0]]
91+
cg_snap.particles.position[group[1]]
92+
- cg_snap.particles.position[group[0]]
9393
)
9494
cg_bond_vec = cg_bond_vec / np.linalg.norm(cg_bond_vec)
9595
for bead_index in group:
9696
if bead_index not in finished_beads:
9797
bead_type = cg_snap.particles.types[
98-
cg_snap.particles.typeid[bead_index]
98+
cg_snap.particles.typeid[bead_index]
9999
]
100100
bead_pos = cg_snap.particles.position[bead_index] * ref_distance
101101
comp = mb.clone(compounds[bead_type])
102102
tail_pos = comp[anchor_particle_indices[1]].xyz[0]
103103
head_pos = comp[anchor_particle_indices[0]].xyz[0]
104-
head_tail_vec = tail_pos - head_pos
104+
head_tail_vec = tail_pos - head_pos
105105
head_tail_vec = head_tail_vec / np.linalg.norm(head_tail_vec)
106106
normal_vec = np.cross(head_tail_vec, cg_bond_vec)
107107
angle = angle_between_vectors(
108-
head_tail_vec,
109-
cg_bond_vec,
110-
degrees=False
111-
)
108+
head_tail_vec, cg_bond_vec, degrees=False
109+
)
112110
comp.rotate(around=normal_vec, theta=angle)
113111
comp.translate_to(bead_pos + pos_adjust)
114112
mb_compounds.append(comp)
115113
bead_to_comp_dict[bead_index] = comp
116114
finished_beads.add(bead_index)
117115
fg_compound.add(comp)
118-
116+
119117
tail_comp = bead_to_comp_dict[group[0]]
120118
tail_comp_particle = tail_comp[anchor_particle_indices[1]]
121119
head_comp = bead_to_comp_dict[group[1]]
122120
head_comp_particle = head_comp[anchor_particle_indices[0]]
123-
fg_compound.add_bond(particle_pair=[tail_comp_particle, head_comp_particle])
121+
fg_compound.add_bond(
122+
particle_pair=[tail_comp_particle, head_comp_particle]
123+
)
124124
if energy_minimize:
125125
temp_head = mb.clone(head_comp)
126126
temp_tail = mb.clone(tail_comp)
127127
temp_comp = mb.Compound(subcompounds=[temp_tail, temp_head])
128128
tail_comp_particle = temp_tail[anchor_particle_indices[1]]
129129
head_comp_particle = temp_head[anchor_particle_indices[0]]
130-
temp_comp.add_bond(particle_pair=[tail_comp_particle, head_comp_particle])
130+
temp_comp.add_bond(
131+
particle_pair=[tail_comp_particle, head_comp_particle]
132+
)
131133
print("Running energy minimization")
132134
temp_comp.energy_minimize(steps=500)
133135
temp_tail = temp_comp.children[0]
@@ -139,8 +141,6 @@ def backmap_snapshot_to_compound(
139141
return fg_compound
140142

141143

142-
143-
144144
def backmap_compound(cg_compound):
145145
"""Backmap a fine-grained representation onto a coarse one.
146146

0 commit comments

Comments
 (0)