`reduced_potential` raising exception?
See original GitHub issueI tried this code:
import simtk.openmm as openmm
import openmmtools.testsystems as ts
import openmmtools.cache as cache
import openmmtools.states as states
import simtk.unit as unit
alanine_ts = ts.AlanineDipeptideExplicit()
thermodynamic_state = states.ThermodynamicState(alanine_ts.system, temperature = 300.0*unit.kelvin)
sampler_state = states.SamplerState(alanine_ts.positions, box_vectors=alanine_ts.system.getDefaultPeriodicBoxVectors())
context, integrator = cache.global_context_cache.get_context(thermodynamic_state)
sampler_state.apply_to_context(context, ignore_velocities=True)
print(thermodynamic_state.reduced_potential(sampler_state))
And I get the following exception:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/Users/grinawap/anaconda/lib/python3.5/site-packages/simtk/unit/quantity.py in _change_units_with_factor(self, new_unit, factor, post_multiply)
675 if post_multiply:
--> 676 value = self._value * factor # works for number, numpy.array, or vec3, e.g.
677 else:
TypeError: unsupported operand type(s) for *: 'float' and 'NoneType'
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
/Users/grinawap/anaconda/lib/python3.5/site-packages/simtk/unit/quantity.py in _scale_sequence(self, value, factor, post_multiply)
690 if post_multiply:
--> 691 value = value*factor
692 else:
TypeError: unsupported operand type(s) for *: 'float' and 'NoneType'
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
/Users/grinawap/anaconda/lib/python3.5/site-packages/simtk/unit/quantity.py in _scale_sequence(self, value, factor, post_multiply)
699 else:
--> 700 for i in range(len(value)):
701 value[i] = value[i]*factor
TypeError: object of type 'float' has no len()
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
<ipython-input-1-8d4437b36778> in <module>()
12 context, integrator = cache.global_context_cache.get_context(thermodynamic_state)
13 sampler_state.apply_to_context(context, ignore_velocities=True)
---> 14 print(thermodynamic_state.reduced_potential(sampler_state))
/Users/grinawap/anaconda/lib/python3.5/site-packages/openmmtools-0.13.1-py3.5.egg/openmmtools/states.py in reduced_potential(self, context_state)
635 beta = 1.0 / (unit.BOLTZMANN_CONSTANT_kB * self.temperature)
636 reduced_potential = potential_energy
--> 637 reduced_potential = reduced_potential / unit.AVOGADRO_CONSTANT_NA
638 pressure = self.pressure
639 if pressure is not None:
/Users/grinawap/anaconda/lib/python3.5/site-packages/simtk/unit/quantity.py in __rtruediv__(self, other)
424 else:
425 # print "R scalar / quantity"
--> 426 return other * pow(self, -1.0)
427 # return Quantity(other / self._value, pow(self.unit, -1.0))
428
/Users/grinawap/anaconda/lib/python3.5/site-packages/simtk/unit/quantity.py in __rmul__(self, other)
387 else:
388 # print "scalar * quantity"
--> 389 return self._change_units_with_factor(self.unit, other, post_multiply=True)
390 # return Quantity(other * self._value, self.unit)
391
/Users/grinawap/anaconda/lib/python3.5/site-packages/simtk/unit/quantity.py in _change_units_with_factor(self, new_unit, factor, post_multiply)
680 except TypeError:
681 value = copy.deepcopy(self._value)
--> 682 result = Quantity(self._scale_sequence(value, factor, post_multiply), new_unit)
683 if (new_unit.is_dimensionless()):
684 return result._value
/Users/grinawap/anaconda/lib/python3.5/site-packages/simtk/unit/quantity.py in _scale_sequence(self, value, factor, post_multiply)
710 value = tuple([self._scale_sequence(x, factor, post_multiply) for x in value])
711 else:
--> 712 for i in range(len(value)):
713 value[i] = self._scale_sequence(value[i], factor, post_multiply)
714 return value
TypeError: object of type 'float' has no len()
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Raising exceptions when an exception is already present in ...
Answering to question 3, you can use: raise B('second') from None. Which will remove the exception A traceback. Traceback (most recent call ...
Read more >Should exceptions be raised higher up or lower down or both?
You definitely want to throw exception when things go "badly wrong", and that tends to be lower down in the layers of code....
Read more >Built-in Exceptions — Python 3.11.1 documentation
User code can raise built-in exceptions. This can be used to test an exception handler or to report an error condition “just like”...
Read more >How to Handle and Raise Exceptions in Python — 12 Things ...
We can handle multiple exceptions in the except clause. We'll simply wrap possible exceptions in a tuple , as shown in Line 6...
Read more >How to Throw Exceptions in Python - Rollbar
This article will show you how to raise exceptions in your Python code and how to address exceptions. Difference Between Python Syntax Errors ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks! That seems to work!
Hmm. Let me see if I can reproduce it!