[MMTK] Re: Can't index a ParticleVectorSet -universe not passed?

Dr. Seth Olsen seth.olsen at gmail.com
Thu Aug 4 08:53:53 CEST 2005


Hi MMTKers,

Never mind, I have solved the problem (and found a bug in the code possibly)!  

In ../site-packages/MMTK/Subspace.py I changed line 36 I changed:

       return ParticleProperties.ParticleVector(universe, self.array[i])

to:

       return ParticleProperties.ParticleVector(self.universe, self.array[i])

The required functionality works fine now and I can call any element
of any member in the ParticleVectorSet.

Strange that I looked at this for hours last night and didn't
realize....   Viva python (and MMTK) for it's breezy learning curve!

Cheers,

Seth


On 8/4/05, Dr. Seth Olsen <seth.olsen at gmail.com> wrote:
> Hi MMTKers,
> 
> I have run into an error when I display a generated basis for a
> subspace.   When I generate a subspace basis object 'gh' and attempt
> to index it to find the elements on a particular atom, I get an error
> from __getitem__ in the particle vector class which states:
> >>> gh[1]
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "/usr/local/lib/python2.3/site-packages/MMTK/Subspace.py", line
> 36, in __getitem__
>     return ParticleProperties.ParticleVector(universe, self.array[i])
> NameError: global name 'universe' is not defined
> 
> However, I did define a universe 'uni' and used this universe to
> generate the particle vectors defining the subspace and the subspace
> 'branchplane' itself.  Everything else checks out - the dimensions &
> elements of the vectors, the projection of another vector on the
> subspace & complement etc.   Furthermore, I can index other
> ParticleVectors just fine using g[i] where g is a ParticleVector and i
> is an integer in the appropriate range.
> 
> Why is the correct universe object not being passed?
> 
> A complete log of my session follows:
> 
> >>> import molprotools            #(import collection of my own
> routines to parse molpro files)
> >>> file=open('m0tac1211s2sps0s1opt.out','r')
> >>> lines=file.readlines()
> >>> geovec=molprotools.get_geovecs(lines).pop()  #(read final geometry
> in CI optimization)
> >>> import Numeric
> >>> geo3d=Numeric.reshape(geovec,(-1,3))  #(reshape geo to shape (natoms,3))
> >>> names=molprotools.get_names(lines)    #(get atom names (which
> indicate element))
> >>> len(names)
> 26                                    #(check sizes of arrays - fine)
> >>> len(geo3d)
> 26
> >>> molecule=molprotools.makeMMTKgroup(names,geovec,verbose=1) #(turn
> into MMTK Collection)
> makeMMTKgroup returns a chemical object with 26 atoms:
> [Atom oxygen, Atom oxygen, Atom oxygen, Atom carbon, Atom carbon, Atom
> carbon, Atom carbon, Atom carbon, Atom carbon, Atom carbon, Atom
> carbon, Atom carbon, Atom carbon, Atom carbon, Atom carbon, Atom
> nitrogen, Atom nitrogen, Atom nitrogen, Atom hydrogen, Atom hydrogen,
> Atom hydrogen, Atom hydrogen, Atom hydrogen, Atom hydrogen, Atom
> hydrogen, Atom hydrogen]
> group has 78 degrees of freedom
> >>> molecule
> <MMTK.Collection.Collection instance at 0xf6c2ac6c>
> >>> molecule.atomList()
> [Atom oxygen, Atom oxygen, Atom oxygen, Atom carbon, Atom carbon, Atom
> carbon, Atom carbon, Atom carbon, Atom carbon, Atom carbon, Atom
> carbon, Atom carbon, Atom carbon, Atom carbon, Atom carbon, Atom
> nitrogen, Atom nitrogen, Atom nitrogen, Atom hydrogen, Atom hydrogen,
> Atom hydrogen, Atom hydrogen, Atom hydrogen, Atom hydrogen, Atom
> hydrogen, Atom hydrogen]
> >>> from MMTK.Universe import *
> >>> uni=InfiniteUniverse()      #(create universe)
> >>> uni
> InfiniteUniverse  containing 0 objects.
> >>> uni.addObject(molecule)
> >>> uni
> InfiniteUniverse  containing 26 objects.
> >>> gvec=molprotools.get_gvecs(lines).pop()  #(read gradient difference vector)
> >>> gvec3d=Numeric.reshape(gvec,(-1,3))    #(change shape to (natoms,3))
> >>> g=MMTK.ParticleVector(uni,gvec3d)     #(make into particle Vector)
> >>> g
> <MMTK.ParticleProperties.ParticleVector instance at 0xf6c2abec>
> >>> hvec=molprotools.get_hvecs(lines).pop()  #(read derivative coupling vector)
> >>> hvec3d=Numeric.reshape(hvec,(-1,3))    #(reshape into (natoms,3))
> >>> h=MMTK.ParticleVector(uni,hvec3d)   #(make into particle vector)
> >>> h
> <MMTK.ParticleProperties.ParticleVector instance at 0xf6c2ae6c>
> >>> h[1]
> Vector(-6.9562300000000003e-05,-0.0099316344999999997,-0.017860772)
> #(check - fine)
> >>> from MMTK.Subspace import *
> >>> branchplane=Subspace(uni,[g,h])  #(generate branching plane from g & h)
> >>> branchplane
> <MMTK.Subspace.Subspace instance at 0xf6a0f7cc>
> >>> gh=branchplane.getBasis()   #(assign orthonormal basis 'gh')
> >>> gh[1]    #(ask for element of gh for checking)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "/usr/local/lib/python2.3/site-packages/MMTK/Subspace.py", line
> 36, in __getitem__
>     return ParticleProperties.ParticleVector(universe, self.array[i])
> NameError: global name 'universe' is not defined
> 
> 
> Am I indexing the ParticleVectorSet in a non-appropriate way?  Does
> anybody know what is going on with this?  I've checked the code and I
> can't seem to find where the problem is - as can be seen above, the
> individual ParticleVectors index just fine, but the ParticleVectorSet
> does not (even though the offending line calls only ParticleVector).
> 
> 
> Cheers,
> 
> Seth\
> 
> --
> ccmsccmsccmsccmsccmsccmsccmsccmsccmsccmsccmsccmsccmsccmsccmsccms
> 
> Dr Seth Olsen, PhD
> Postdoctoral Fellow, Biomolecular Modeling Group
> Centre for Computational Molecular Science
> Chemistry Building,
> The University of Queensland
> Qld 4072, Brisbane, Australia
> 
> tel (617) 33653732
> fax (617) 33654623
> email: s.olsen1 at uq.edu.au
> Web: www.ccms.uq.edu.au
> 
> ccmsccmsccmsccmsccmsccmsccmsccmsccmsccmsccmsccmsccmsccmsccmsccms
> 


-- 
ccmsccmsccmsccmsccmsccmsccmsccmsccmsccmsccmsccmsccmsccmsccmsccms

Dr Seth Olsen, PhD
Postdoctoral Fellow, Biomolecular Modeling Group
Centre for Computational Molecular Science
Chemistry Building,
The University of Queensland
Qld 4072, Brisbane, Australia

tel (617) 33653732
fax (617) 33654623
email: s.olsen1 at uq.edu.au
Web: www.ccms.uq.edu.au 

ccmsccmsccmsccmsccmsccmsccmsccmsccmsccmsccmsccmsccmsccmsccmsccms



More information about the mmtk mailing list