diff --git a/README.md b/README.md
index 8d2d402..c1ad429 100644
--- a/README.md
+++ b/README.md
@@ -25,7 +25,7 @@ nbmolviz.visualize(benzene)
## Dev install
-Requires npm.
+Requires npm. (Can get through `conda install -c conda-forge nodejs`)
$ git clone https://github.com/autodesk/notebook-molecular-visualization.git
$ cd notebook-molecular-visualization
diff --git a/nbmolviz/__init__.py b/nbmolviz/__init__.py
index 6d0a7e2..cee0393 100644
--- a/nbmolviz/__init__.py
+++ b/nbmolviz/__init__.py
@@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+from __future__ import print_function
import os as _os
MDTVERSION = '0.8.0'
@@ -49,9 +50,9 @@ def _enable_nbextension():
try:
import notebook
if not notebook.nbextensions.check_nbextension('nbmolviz-js'):
- print 'Installing Jupyter nbmolviz-js extension...',
+ print('Installing Jupyter nbmolviz-js extension...', end='')
notebook.nbextensions.install_nbextension_python('nbmolviz')
- print 'done'
+ print('done')
notebook.nbextensions.enable_nbextension_python('widgetsnbextension')
notebook.nbextensions.enable_nbextension_python('nbmolviz')
except Exception as e:
diff --git a/nbmolviz/base/molviz2d.py b/nbmolviz/base/molviz2d.py
index 777098c..dc454db 100644
--- a/nbmolviz/base/molviz2d.py
+++ b/nbmolviz/base/molviz2d.py
@@ -148,5 +148,5 @@ def set_colors(self, colormap, render=True):
Args:
colormap(Mapping[str,List[Atoms]]): mapping of colors to atoms
"""
- for color, atoms in colormap.iteritems():
+ for color, atoms in colormap.items():
self.set_color(atoms=atoms, color=color)
diff --git a/nbmolviz/base/molviz3d.py b/nbmolviz/base/molviz3d.py
index e4695b0..e61f554 100644
--- a/nbmolviz/base/molviz3d.py
+++ b/nbmolviz/base/molviz3d.py
@@ -12,7 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import numpy as np
-from StringIO import StringIO
+try:
+ from StringIO import StringIO
+except ImportError:
+ from io import StringIO
from traitlets import Bool, Dict, Float, List, Set, Unicode
from ..utils import JSObject, translate_color, in_pixels
@@ -150,7 +153,7 @@ def set_colors(self, colormap):
colormap(Mapping[str,List[Atoms]]): mapping of colors to atoms
"""
styles = dict(self.styles)
- for color, atoms in colormap.iteritems():
+ for color, atoms in colormap.items():
styles = MolViz3D.get_styles_for_color(color, atoms, styles)
self.styles = styles
@@ -490,9 +493,9 @@ def _grid_to_cube(grid,f=None):
print >> fobj, 1, 1
# finally, write out all the grid values
# ival = 0
- for ix in xrange(grid.npoints):
- for iy in xrange(grid.npoints):
- for iz in xrange(grid.npoints):
+ for ix in range(grid.npoints):
+ for iy in range(grid.npoints):
+ for iz in range(grid.npoints):
print >> fobj, grid.fxyz[ix, iy, iz],
# ival += 1
# if ival%6 == 0: print >> fobj #newline
diff --git a/nbmolviz/uielements/configurator.py b/nbmolviz/uielements/configurator.py
index 15f24fc..5d26cfb 100644
--- a/nbmolviz/uielements/configurator.py
+++ b/nbmolviz/uielements/configurator.py
@@ -71,7 +71,7 @@ def __init__(self, paramlist, paramdefs, title=None):
def reset_values(self, *args):
reset_params = set()
- for name, value in self.paramlist.iteritems():
+ for name, value in self.paramlist.items():
if value is not None:
self.selectors[name].selector.value = value
reset_params.add(name)
@@ -82,7 +82,7 @@ def reset_values(self, *args):
self.show_relevant_fields()
def apply_values(self, *args):
- for paramname, selector in self.selectors.iteritems():
+ for paramname, selector in self.selectors.items():
self.paramlist[paramname] = selector.selector.value
self.currentconfig.value = self._pretty_print_config()
self.show_relevant_fields()
@@ -91,7 +91,7 @@ def _pretty_print_config(self):
def cleanse(v):
if isinstance(v, (float,int)): return v
else: return str(v)
- return yaml.dump({k: cleanse(v) for k, v in self.paramlist.iteritems()},
+ return yaml.dump({k: cleanse(v) for k, v in self.paramlist.items()},
default_flow_style=False)
def show_relevant_fields(self):
diff --git a/nbmolviz/uielements/logwidget.py b/nbmolviz/uielements/logwidget.py
index da3d6d5..439120f 100644
--- a/nbmolviz/uielements/logwidget.py
+++ b/nbmolviz/uielements/logwidget.py
@@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+from __future__ import print_function
import logging
from collections import OrderedDict
@@ -47,7 +48,7 @@ def display_log(obj, title=None, show=False):
"""
if not widgets_enabled:
- print obj
+ print(obj)
return
if _current_tabs is None: # just display the damn thing
@@ -178,7 +179,7 @@ def _write(self, string):
self.active = True
self.value += string.strip() + '\n'
else:
- print string.strip()
+ print(string.strip())
# temporary so that we can use this like a logging module later
error = warning = info = handled = debug = status = _write
@@ -193,7 +194,7 @@ def _capture_logging_displays(display=False, **kwargs):
else:
_current_tabs = None
enable_logging_widgets(False)
- print 'Failed to create UI logging system. Logging widgets disabled'
+ print('Failed to create UI logging system. Logging widgets disabled')
def _finalize_logging_displays(display=True, **kwargs):
diff --git a/nbmolviz/utils.py b/nbmolviz/utils.py
index 36b6ba0..f6ef7bc 100644
--- a/nbmolviz/utils.py
+++ b/nbmolviz/utils.py
@@ -35,8 +35,12 @@
'Uuh': 116, 'Uuo': 118, 'Uup': 115, 'Uuq': 114, 'Uus': 117, 'Uut': 113, 'V': 23,
'W': 74, 'Xe': 54, 'Y': 39, 'Yb': 70, 'Zn': 30, 'Zr': 40}
-elements = {atnum:el for el,atnum in atomic_numbers.iteritems()}
+elements = {atnum:el for el,atnum in atomic_numbers.items()}
+try:
+ basestring
+except NameError:
+ basestring = str
def make_layout(layout=None, **kwargs):
from ipywidgets import Layout
@@ -44,7 +48,7 @@ def make_layout(layout=None, **kwargs):
if layout is None:
layout = Layout()
- for key, val in kwargs.iteritems():
+ for key, val in kwargs.items():
# note that this is the type of the class descriptor, not the instance attribute
if isinstance(getattr(Layout, key), traitlets.Unicode):
val = in_pixels(val)
diff --git a/nbmolviz/viewers/viewer2d.py b/nbmolviz/viewers/viewer2d.py
index 109ad59..f30e4eb 100644
--- a/nbmolviz/viewers/viewer2d.py
+++ b/nbmolviz/viewers/viewer2d.py
@@ -88,7 +88,7 @@ def to_graph(self, atoms):
nodes[-1].update({'atom': '',
'size': 0.5,
'color': 'darkgray'})
- for neighbor, order in atom1.bond_graph.iteritems():
+ for neighbor, order in atom1.bond_graph.items():
if neighbor not in self.atom_indices: continue
nbr_idx = self.atom_indices[neighbor]
if nbr_idx < i1:
@@ -178,7 +178,7 @@ def to_graph(self, atoms):
# Add distance restraints for non-bonded atoms
for i1, atom1 in enumerate(atoms):
- for i2 in xrange(i1 + 1, len(atoms)):
+ for i2 in range(i1 + 1, len(atoms)):
atom2 = atoms[i2]
if atom1 in atom2.bond_graph: continue
diff --git a/nbmolviz/viewers/viewer3d.py b/nbmolviz/viewers/viewer3d.py
index 07da24f..86cb824 100644
--- a/nbmolviz/viewers/viewer3d.py
+++ b/nbmolviz/viewers/viewer3d.py
@@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+from __future__ import print_function
import sys
import IPython.display as dsp
@@ -142,7 +143,7 @@ def set_color(self, color, atoms=None, _store=True):
@utils.doc_inherit
def set_colors(self, colormap, _store=True):
if _store:
- for color, atoms in colormap.iteritems():
+ for color, atoms in colormap.items():
for atom in atoms:
self._colored_as[atom] = color
return super(GeometryViewer, self).set_colors(colormap)
@@ -247,8 +248,8 @@ def draw_atom_vectors(self, vecs, rescale_to=1.75,
scale = (lengths.max() / rescale_to) # units of [vec units] / angstrom
if hasattr(scale,'defunits'): scale = scale.defunits()
arrowvecs = vecarray / scale
- print 'Arrow scale: {q:.3f} {unit} per {native}'.format(q=scale, unit=unit,
- native=self.DISTANCE_UNITS)
+ print('Arrow scale: {q:.3f} {unit} per {native}'.format(q=scale, unit=unit,
+ native=self.DISTANCE_UNITS))
shapes = []
for atom, vecarray in zip(self.mol.atoms, arrowvecs):
if vecarray.norm() < 0.2: continue
diff --git a/nbmolviz/widget_utils.py b/nbmolviz/widget_utils.py
index 5a1b1b2..3d05985 100644
--- a/nbmolviz/widget_utils.py
+++ b/nbmolviz/widget_utils.py
@@ -1,3 +1,4 @@
+from __future__ import print_function
import sys
def can_use_widgets():
@@ -19,7 +20,7 @@ def can_use_widgets():
return False
if int(ipy.__version__.split('.')[0]) < 6:
- print 'WARNING: widgets require ipywidgets 6.0 or later'
+ print('WARNING: widgets require ipywidgets 6.0 or later')
return False
return True
diff --git a/nbmolviz/widgets/components.py b/nbmolviz/widgets/components.py
index 3b03036..a8d1f78 100644
--- a/nbmolviz/widgets/components.py
+++ b/nbmolviz/widgets/components.py
@@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+from __future__ import print_function
import collections
import ipywidgets as ipy
@@ -35,9 +36,10 @@ def indices_to_value(self, atom_indices, atoms):
Turn atom objects into a value to display
"""
def atoms_to_value(self, atoms):
- if len(atoms) == 0:
+ natom = len(list(atoms))
+ if natom == 0:
return 'No selection'
- elif len(atoms) == 1:
+ elif natom == 1:
atom = atoms[0]
res = atom.residue
chain = res.chain
@@ -49,7 +51,7 @@ def atoms_to_value(self, atoms):
lines.append("Atom %s (%s), index %d
" % (atom.name, atom.symbol, atom.index))
return '\n'.join(lines)
- elif len(atoms) > 1:
+ elif natom > 1:
atstrings = ['%s, index %s / res %s, index %s / chain %s' %
(a.name, a.index, a.residue.resname, a.residue.index, a.chain.name)
for a in atoms]
@@ -170,7 +172,7 @@ def parse_value(self, *args):
match = utils.GETFLOAT.search(s)
if match is None:
self.readout.value = self.formatstring.format(self.slider.value)
- print "Couldn't parse string %s" % s
+ print("Couldn't parse string %s" % s)
return
else:
f = float(s[match.start():match.end()])
diff --git a/nbmolviz/widgets/parameterization.py b/nbmolviz/widgets/parameterization.py
index fa0663d..d4a2f1e 100644
--- a/nbmolviz/widgets/parameterization.py
+++ b/nbmolviz/widgets/parameterization.py
@@ -21,6 +21,7 @@
This is currently tied to ambertools and tleap! It will need to be made generic if/when
another method for assigning forcefields is added.
"""
+from __future__ import print_function
import collections
import ipywidgets as ipy
@@ -35,9 +36,9 @@ def show_parameterization_results(errormessages, molin, molout=None):
uibase.display_log(report, title='ERRORS/WARNINGS', show=True)
else:
- print 'Forcefield assignment: %s' % ('Success' if molout is not None else 'Failure')
+ print('Forcefield assignment: %s' % ('Success' if molout is not None else 'Failure'))
for err in errormessages:
- print utils.html_to_text(err.desc)
+ print(utils.html_to_text(err.desc))
diff --git a/nbmolviz/widgets/selector.py b/nbmolviz/widgets/selector.py
index c6b96c5..e81214a 100644
--- a/nbmolviz/widgets/selector.py
+++ b/nbmolviz/widgets/selector.py
@@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# TODO: catch and log event exceptions
+from __future__ import print_function
import ipywidgets as ipy
from moldesign import utils
@@ -126,7 +127,7 @@ def handle_selection_event(self, selection):
if self.value_selects in selection:
self.value = selection[self.value_selects]
except Exception as exc:
- print 'ERROR: (ignored) %s' % exc
+ print('ERROR: (ignored) %s' % exc)
self.__hold_fire = False
diff --git a/nbmolviz/widgets/trajectory.py b/nbmolviz/widgets/trajectory.py
index 3510811..62b143b 100644
--- a/nbmolviz/widgets/trajectory.py
+++ b/nbmolviz/widgets/trajectory.py
@@ -76,7 +76,7 @@ def animate(self, fps=None):
fps = mdt.utils.if_not_none(fps, self.default_fps)
self.slider.value = 0
spf = 1.0 / fps
- for i in xrange(self.viewer.num_frames):
+ for i in range(self.viewer.num_frames):
t0 = time.time()
self.slider.value = i
dt = time.time() - t0