Becksteinlab / GromacsWrapper

GromacsWrapper wraps system calls to GROMACS tools into thin Python classes (GROMACS 4.6.5 - 2024 supported).
https://gromacswrapper.readthedocs.org
GNU General Public License v3.0
168 stars 53 forks source link

itp merging script #10

Closed jandom closed 12 years ago

jandom commented 12 years ago

Hi Oli,

I'm attempting to recreate a tool that everybody has - a topolgy merging script. Such script could be used to construct a complete phospholipid lipid topology from tail and head-group topologies, or to attach a lipid anchor to a protein topology.

I've figured out how to change the atoms/bonds/angles and other fields, to ensure a working topology when "n" itp files are merged; however, i'm stuck trying to write out an existing molecule:

// Concatenate 'n' molecules, the atom numbering has been corrected at this stage atoms = np.concatenate([m.sections['header'].sections['moleculetype'].sections['atoms'].data for m in molecules])molecule molecule = molecules[0] molecule.sections['header'].sections['moleculetype'].sections['atoms'].data = atoms ... AttributeError: can't set attribute

Sure, 'data' is an attribute. I don't think this should be changed; I'd rather create an in-memory topology file from scratch. How could one instantiate such a dummy object and fill it with the atom/bond/angles/etc sections created by user?

orbeckst commented 12 years ago

I made ITPdata.data a managed attribute (reading ITPdata.data) because I wanted to shield it from accidental changes and I wanted to parse/cache the records lazily. Of course you can change individual elements by accessing data[:] but you cannot grow/reassign the recarray as you want to.

You could simply add a method

set_data(self, data):
    self.__data = data

(or add a fset method to the property). The ITPdata.set_data method would have the advantage that it makes explicit that you're doing something rather hack-ish here.

I can't think of a easy way to create an empty ITP structure with, say a fixed number of atoms, bonds, dihedrals etc. The code was not designed with this in mind, sorry. But if you come up with a sensible rewrite then I am very happy to add it.

jandom commented 12 years ago

Let's go with the set_data then, that looks reasonable.

orbeckst commented 12 years ago

Ok.