salilab / pmi

Python Modeling Interface
https://integrativemodeling.org/nightly/doc/ref/namespaceIMP_1_1pmi.html
12 stars 11 forks source link

What to do with selection tuples? #145

Open cgreenberg opened 8 years ago

cgreenberg commented 8 years ago

So in PMI1 a restraint is typically set up with:

x = Restraint(representation = r,
            selection_tuples=[('A',100,150),('B',200,235)],
             resolution=10)

Then the restraint internally does the selection. But now in PMI2 we have nice "handles" and also IMP Selection works great with all resolutions (including densities). We could now just have all restraints be set up like so:

x = Restraint(hiers = [molA[100:150],molB[200:235]],
            resolution=10)

So we'd get rid of selection tuples altogether. What do you think? @Pellarin ?

Pellarin commented 8 years ago

Yes, but we still need backcompatibility. How can we prevent to broke previous code?

benmwebb commented 8 years ago

Why not just pass a Selection object to each PMI restraint, rather than passing Selection-like parameters (e.g. resolution, residue indices) to each one?

cgreenberg commented 8 years ago

I'm all for that. Only problem is that many PMI restraints do the selecting for you - they read in data and select within the passed hierarchy. E.g. crosslink data or elastic networks on SSE elements. Maybe the way to do it is have PMI helper functions which create a selection from input data?

benmwebb commented 8 years ago

Perhaps... or we make Selection itself more flexible.

cgreenberg commented 8 years ago

Proposal after talking with @saltzberg : have all data parsers in IO (including CrosslinkDatabase, DSSPParser, ...) have a select(hier,**kwargs) function which: 1) selects particles in hier according to the underlying data (e.g. gives lists of lists of particle pairs for crosslinks) and 2) admits additional selection keywords. So you could, for example, create a customized XL selection with:

xldb = IMP.pmi.io.crosslink.CrossLinkDataBase()
xldb.create_set_from_file("xlinks.csv")
pps = xldb.select(hier,resolution=0,atom_type=IMP.atom.AtomType("NZ"))
r = IMP.pmi.restraints.CrossLinkingMassSpectrometryRestraint(particle_pair_lists=pps,
                                                             slope=0.0,
                                                             length=21.0,
                                                             label="XL")

Thoughts?

benmwebb commented 8 years ago

1) looks fine but 2) duplicates the existing Selection framework somewhat, so you'd end up writing a lot of duplicated code.

cgreenberg commented 8 years ago

I'd have it internally call IMP Selection and just pass the kwargs on.