mosdef-hub / mbuild

A hierarchical, component based molecule builder
https://mbuild.mosdef.org
Other
171 stars 80 forks source link

issues with translate #142

Closed chrisiacovella closed 8 years ago

chrisiacovella commented 8 years ago

If I try to use the translate command I get an issue with numpy.

For example, I tried running

import mbuild as mb
import random
from mbuild import clone
import numpy as np

class MonoLJ(mb.Compound):
    def __init__(self):
        super(MonoLJ, self).__init__()
        lj_particle1 = mb.Atom(name='LJ', pos=[0, 0, 0])
        self.add(lj_particle1)

        lj_particle2 = clone(lj_particle1)
        pos=[1, 0, 0]
        mb.translate(lj_particle2, pos)
        self.add(lj_particle2)

monoLJ = MonoLJ()
monoLJ.visualize()

and get the error: NameError: global name 'np' is not defined

chrisiacovella commented 8 years ago

Also, I'll note I tried using the Grid3DPattern function and i said it couldn't be found. As an example of this error, see tnp_box.py in the examples/tnp folder.

Traceback (most recent call last):
  File "tnp_box.py", line 36, in <module>
    box = main()
  File "tnp_box.py", line 32, in main
    box = TnpBox()
  File "tnp_box.py", line 16, in __init__
    pattern = mb.Grid3DPattern(3, 3, 3)
AttributeError: 'module' object has no attribute 'Grid3DPattern'
ctk3b commented 8 years ago

Can you print the full traceback for the first error? It means you aren't importing numpy correctly somewhere.

For the second problem, are you using the latest mBuild version? We revamped the patterning functionality a bit to give us some future proofing and be able to do some of the more complex things you suggested.

The easiest way for you to currently stay up to date since we'll be fixing lots of things in the coming weeks is to install mbuild like so (I would also recommend doing this in a separate conda environment just to prevent any annoying issues):

git clone https://github.com/iModels/mbuild.git
cd mbuild
python setup.py develop

whenever you want to update just type git pull from anywhere inside the mbuild directory.

In general, people can get the latest mbuild version by using conda install mbuild-dev instead of conda install mbuild. I'll make a note of this in the docs.

chrisiacovella commented 8 years ago

Regarding the first issue, I'm using a built in function to mbuild (and I've tried importing numpy in several ways), so I assume there is some strange bug in there.

I've been working with the current release version trying to find issues. I'll clone the current dev version on my other machine to isolate the cause.

ctk3b commented 8 years ago

I can't really speak the numpy bug without a traceback since I cannot reproduce it on the latest version.

I've added a working version of your example in #152.

There is also some issue with conda that currently prevents snapshots of the latest version being push to anaconda.org. I can't quite figure it out and will try with Janos tomorrow. In the meantime, just follow these steps to stay up to date:

git clone https://github.com/iModels/mbuild.git
cd mbuild
python setup.py develop
# do stuff

# when you want to get the latest version
git pull
chrisiacovella commented 8 years ago
Traceback (most recent call last):
  File "monoLJb.py", line 22, in <module>
    monoLJ = MonoLJ()
  File "monoLJb.py", line 18, in __init__
    mb.translate(lj_particle2, pos)
  File "/Users/cri/anaconda/lib/python2.7/site-packages/mbuild/coordinate_transform.py", line 364, in translate
    atom_positions = Translation(v).apply_to(atom_positions)
  File "/Users/cri/anaconda/lib/python2.7/site-packages/mbuild/coordinate_transform.py", line 22, in apply_to
    A = np.expand_dims(A, axis=0)
NameError: global name 'np' is not defined
ctk3b commented 8 years ago

Ok these should all be covered now.