Skip to content

Commit

Permalink
Merge pull request #2677 from jngrad/torsion-visu
Browse files Browse the repository at this point in the history
Visualization: dihedrals connectivity
  • Loading branch information
fweik authored Apr 24, 2019
2 parents ca2e5f9 + 3c4e073 commit 707a014
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 22 deletions.
57 changes: 39 additions & 18 deletions src/python/espressomd/visualization_mayavi.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ from .particle_data cimport *
from .interactions cimport *
from .system cimport *
from .interactions import NonBondedInteractions
from .interactions cimport BONDED_IA_DIHEDRAL, BONDED_IA_TABULATED

include "myconfig.pxi"

Expand Down Expand Up @@ -64,14 +65,15 @@ cdef class mayaviLive(object):
self.particle_sizes = particle_sizes

# objects drawn
self.points = mlab.quiver3d(
[], [], [], [], [], [], scalars=[], mode="sphere", scale_factor=1, name="Particles")
self.points = mlab.quiver3d([], [], [], [], [], [], scalars=[],
mode="sphere", scale_factor=1,
name="Particles")
self.points.glyph.color_mode = 'color_by_scalar'
self.points.glyph.glyph_source.glyph_source.center = [0, 0, 0]
self.box = mlab.outline(
extent=(0, 0, 0, 0, 0, 0), color=(1, 1, 1), name="Box")
self.arrows = mlab.quiver3d(
[], [], [], [], [], [], scalars=[], mode="2ddash", scale_factor=1, name="Bonds")
self.box = mlab.outline(extent=(0, 0, 0, 0, 0, 0), color=(1, 1, 1),
name="Box")
self.arrows = mlab.quiver3d([], [], [], [], [], [], scalars=[],
mode="2ddash", scale_factor=1, name="Bonds")
self.arrows.glyph.color_mode = 'color_by_scalar'

# state
Expand Down Expand Up @@ -132,22 +134,29 @@ cdef class mayaviLive(object):
if box_changed or not self.running:
self.box.set(bounds=(0, boxl[0], 0, boxl[1], 0, boxl[2]))
if not N_changed:
self.points.mlab_source.set(x=coords[:, 0] % boxl[0], y=coords[:, 1] % boxl[
1], z=coords[:, 2] % boxl[2], u=radii, v=radii, w=radii, scalars=types)
self.points.mlab_source.set(x=coords[:, 0] % boxl[0],
y=coords[:, 1] % boxl[1],
z=coords[:, 2] % boxl[2], u=radii,
v=radii, w=radii, scalars=types)
else:
self.points.mlab_source.reset(x=coords[:, 0] % boxl[0], y=coords[:, 1] % boxl[
1], z=coords[:, 2] % boxl[2], u=radii, v=radii, w=radii, scalars=types)
self.points.mlab_source.reset(x=coords[:, 0] % boxl[0],
y=coords[:, 1] % boxl[1],
z=coords[:, 2] % boxl[2], u=radii,
v=radii, w=radii, scalars=types)
if not self.running:
f.scene.reset_zoom()
self.running = True

if not Nbonds_changed:
if bonds.shape[0] > 0:
self.arrows.mlab_source.set(x=bonds[:, 0], y=bonds[:, 1], z=bonds[
:, 2], u=bonds[:, 3], v=bonds[:, 4], w=bonds[:, 5])
self.arrows.mlab_source.set(x=bonds[:, 0], y=bonds[:, 1],
z=bonds[:, 2], u=bonds[:, 3],
v=bonds[:, 4], w=bonds[:, 5])
else:
self.arrows.mlab_source.reset(x=bonds[:, 0], y=bonds[:, 1], z=bonds[
:, 2], u=bonds[:, 3], v=bonds[:, 4], w=bonds[:, 5], scalars=bonds[:, 6])
self.arrows.mlab_source.reset(x=bonds[:, 0], y=bonds[:, 1],
z=bonds[:, 2], u=bonds[:, 3],
v=bonds[:, 4], w=bonds[:, 5],
scalars=bonds[:, 6])

def update(self):
"""Pull the latest particle information from Espresso.
Expand All @@ -174,8 +183,8 @@ cdef class mayaviLive(object):
cdef IA_parameters * ia
cdef vector[int] bonds

# Using (additional) untyped variables and python constructs in the loop
# will slow it down considerably.
# Using (additional) untyped variables and python constructs in the loop
# will slow it down considerably.
for i in range(N):
p = get_particle_data_ptr(get_particle_data(i))
if not p:
Expand All @@ -193,11 +202,23 @@ cdef class mayaviLive(object):
t = p.bl[k]
k += 1
# Iterate over bond partners and store each connection
for l in range(bonded_ia_params[t].num):
bonds.push_back(i)
if bonded_ia_params[t].num == 3 and bonded_ia_params[t].type \
in (BONDED_IA_DIHEDRAL, BONDED_IA_TABULATED):
for l in range(2):
bonds.push_back(i)
bonds.push_back(p.bl[k])
bonds.push_back(t)
k += 1
bonds.push_back(p.bl[k - 1])
bonds.push_back(p.bl[k])
bonds.push_back(t)
k += 1
else:
for l in range(bonded_ia_params[t].num):
bonds.push_back(i)
bonds.push_back(p.bl[k])
bonds.push_back(t)
k += 1
j += 1
assert j == len(self.system.part)
cdef int Nbonds = bonds.size() // 3
Expand Down
15 changes: 11 additions & 4 deletions src/python/espressomd/visualization_opengl.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ include "myconfig.pxi"
from copy import deepcopy
import espressomd
from espressomd.particle_data import ParticleHandle
from espressomd.interactions cimport BONDED_IA_DIHEDRAL, BONDED_IA_TABULATED


class openGLLive(object):
Expand Down Expand Up @@ -463,7 +464,7 @@ class openGLLive(object):
constraint_types.append(c.get_parameter('particle_type'))
all_types.update(constraint_types)

# COLLECT ALL ACTIVCE NONBONDED INTERACTIONS
# COLLECT ALL ACTIVE NONBONDED INTERACTIONS
all_non_bonded_inters = [x for x in dir(self.system.non_bonded_inter[0, 0]) if not x.startswith(
'__') and not x == 'type1' and not x == 'type2']
for t1 in all_types:
Expand Down Expand Up @@ -873,10 +874,16 @@ class openGLLive(object):
for i, p in enumerate(self.system.part):
bs = p.bonds
for b in bs:
t = b[0].type_number()
# b[0]: Bond, b[1:] Partners
for p in b[1:]:
self.bonds.append([i, p, t])
t = b[0].type_number()
if len(b) == 4 and t in (BONDED_IA_DIHEDRAL,
BONDED_IA_TABULATED):
self.bonds.append([i, b[1], t])
self.bonds.append([i, b[2], t])
self.bonds.append([b[2], b[3], t])
else:
for p in b[1:]:
self.bonds.append([i, p, t])

def _draw_text(
self,
Expand Down

0 comments on commit 707a014

Please sign in to comment.