madscatt / zazmol

Library for defining molecular objects to create simulation and analysis programs To install: python setup.py install dependencies: numpy, mocker
GNU General Public License v3.0
0 stars 2 forks source link

Consider defining a numpy type to represent particles #50

Closed StevenCHowell closed 7 years ago

StevenCHowell commented 7 years ago

I am not sure this actually makes sense to implement, partly because it would break lots of code that depends on SASMOL, but I wanted to mention the idea of defining a numpy type to store SasMol objects. Here is an example:

particle_dtype = numpy.dtype({'names':['x','y','z','mass','resid','atom','name'], 
                             'formats':[numpy.double, 
                                        numpy.double, 
                                        numpy.double, 
                                        numpy.double, 
                                        numpy.int,
                                        'U1',
                                        'U4']})

# create a 10 atom CA backbone
mol = numpy.zeros(10, dtype=particle_dtype)
mol['name'] = 'CA'
mol['atom'] = 'C'
# mol['mass'] = mass_dict['CA'] #  could have a dictionary with the mass values for different atom types
# etc ... (only initialized some of the values...)

print(mol)

with the output being

array([(0.0, 0.0, 0.0, 0.0, 0, 'C', 'CA'),
       (0.0, 0.0, 0.0, 0.0, 0, 'C', 'CA'),
       (0.0, 0.0, 0.0, 0.0, 0, 'C', 'CA'),
       (0.0, 0.0, 0.0, 0.0, 0, 'C', 'CA'),
       (0.0, 0.0, 0.0, 0.0, 0, 'C', 'CA'),
       (0.0, 0.0, 0.0, 0.0, 0, 'C', 'CA'),
       (0.0, 0.0, 0.0, 0.0, 0, 'C', 'CA'),
       (0.0, 0.0, 0.0, 0.0, 0, 'C', 'CA'),
       (0.0, 0.0, 0.0, 0.0, 0, 'C', 'CA'),
       (0.0, 0.0, 0.0, 0.0, 0, 'C', 'CA')],
      dtype=[('x', '<f8'), ('y', '<f8'), ('z', '<f8'), ('mass', '<f8'), ('resid', '<i8'), ('atom', '<U1'), ('name', '<U4')])

As is, atom properties are not connected in the code, e.g., an atom's name and coordinates are elements of different data structures. This unifies them.

StevenCHowell commented 7 years ago

The advantage this would provide is mentioned in #52.