Skip to content

Commit

Permalink
Conform model attribute to developer guide
Browse files Browse the repository at this point in the history
Relates #163
  • Loading branch information
sethaxen committed Jun 25, 2018
1 parent 90ea390 commit 4adce53
Show file tree
Hide file tree
Showing 15 changed files with 302 additions and 215 deletions.
31 changes: 18 additions & 13 deletions pyext/src/dof/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class DegreesOfFreedom(object):
Call the various create() functions to get started.
Can get all enabled movers with get_movers(). Pass this to ReplicaExchange0.
"""
def __init__(self,mdl):
self.mdl = mdl
def __init__(self,model):
self.model = model
self.movers = []
self.fb_movers = [] #stores movers corresponding to floppy parts
self.rigid_bodies = [] #stores rigid body objects
Expand All @@ -55,6 +55,11 @@ def __init__(self,mdl):
# internal mover = [mover obj, list of particles, enabled?] ?
# mover map = {particles/rbs : movers}

@property
@IMP.deprecated_method("3.0", "Model should be accessed with `.model`.")
def mdl(self):
return self.model

def create_rigid_body(self,
rigid_parts,
nonrigid_parts=None,
Expand Down Expand Up @@ -335,15 +340,15 @@ def setup_md(self,
vykey = IMP.FloatKey('vy')
vzkey = IMP.FloatKey('vz')
hiers = IMP.pmi.tools.input_adaptor(hspec,flatten=True)
mdl = hiers[0].get_model()
model = hiers[0].get_model()
all_ps = []
for hl in hiers:
for h in IMP.core.get_leaves(hl):
p = h.get_particle()
IMP.core.XYZ(mdl,p.get_index()).set_coordinates_are_optimized(True)
mdl.add_attribute(vxkey,p.get_index(),0.0)
mdl.add_attribute(vykey,p.get_index(),0.0)
mdl.add_attribute(vzkey,p.get_index(),0.0)
IMP.core.XYZ(model,p.get_index()).set_coordinates_are_optimized(True)
model.add_attribute(vxkey,p.get_index(),0.0)
model.add_attribute(vykey,p.get_index(),0.0)
model.add_attribute(vzkey,p.get_index(),0.0)
all_ps.append(p)
return all_ps

Expand Down Expand Up @@ -399,11 +404,11 @@ def constrain_symmetry(self,


if type=="RIGID_BODY":
p=IMP.Particle(self.mdl)
p=IMP.Particle(self.model)
p.set_name("RigidBody_Symmetry")
rb=IMP.core.RigidBody.setup_particle(p,IMP.algebra.ReferenceFrame3D(transform))
for cp in [(10,0,0),(0,10,0),(0,0,10)]:
p=IMP.Particle(self.mdl)
p=IMP.Particle(self.model)
IMP.core.XYZ.setup_particle(p,cp)
rb.add_member(p)
sm = IMP.core.TransformationSymmetry(rb.get_particle_index())
Expand All @@ -428,9 +433,9 @@ def constrain_symmetry(self,
#self._rb2mov[rb] = [rb_mover_tr] #dictionary relating rb to movers

lsc = IMP.container.ListSingletonContainer(
self.mdl,[p.get_particle().get_index() for p in clones_rbs+clones_beads])
self.model,[p.get_particle().get_index() for p in clones_rbs+clones_beads])
c = IMP.container.SingletonsConstraint(sm, None, lsc)
self.mdl.add_score_state(c)
self.model.add_score_state(c)
print('Created symmetry restraint for',len(ref_rbs),'rigid bodies and',
len(ref_beads),'flexible beads')

Expand All @@ -439,7 +444,7 @@ def constrain_symmetry(self,

#sym_movers = [m for cl in clones_rbs for m in self._rb2mov[cl]]
#self.movers = [m for m in self.movers if m not in sym_movers]
self.mdl.update()
self.model.update()


def __repr__(self):
Expand All @@ -459,7 +464,7 @@ def optimize_flexible_beads(self, nsteps, temperature=1.0):
for n, fb in enumerate(self.get_flexible_beads()):
pts.add_particle(fb, "Floppy_Bodies", 1.0, "Flexible_Bead_" + str(n))
if len(pts.get_particles_to_sample()) > 0:
mc = IMP.pmi.samplers.MonteCarlo(self.mdl, [pts], temperature)
mc = IMP.pmi.samplers.MonteCarlo(self.model, [pts], temperature)
print("optimize_flexible_beads: optimizing %i flexible beads" % len(self.get_flexible_beads()))
mc.optimize(nsteps)
else:
Expand Down
26 changes: 19 additions & 7 deletions pyext/src/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def convert_chain(ch):
sses['beta'].append(beta_dict[beta_sheet])
return sses

def save_best_models(mdl,
def save_best_models(model,
out_dir,
stat_files,
number_of_best_scoring_models=10,
Expand All @@ -141,7 +141,7 @@ def save_best_models(mdl,
override_rmf_dir=None):
"""Given a list of stat files, read them all and find the best models.
Save to a single RMF along with a stat file.
@param mdl The IMP Model
@param model The IMP Model
@param out_dir The output directory. Will save 3 files (RMF, stat, summary)
@param stat_files List of all stat files to collect
@param number_of_best_scoring_models Num best models to gather
Expand Down Expand Up @@ -227,7 +227,7 @@ def save_best_models(mdl,
stat = open(out_stat_fn,'w')
rh0 = RMF.open_rmf_file_read_only(
os.path.join(root_directory_of_stat_file,all_fields[rmf_file_key][0]))
prots = IMP.rmf.create_hierarchies(rh0,mdl)
prots = IMP.rmf.create_hierarchies(rh0,model)
del rh0
outf = RMF.create_rmf_file(out_rmf_fn)
IMP.rmf.add_hierarchies(outf,prots)
Expand Down Expand Up @@ -574,13 +574,19 @@ def get_bead_sizes(model,rmf_tuple,rmsd_calculation_components=None,state_number
class RMSDOutput(object):
"""A helper output based on dist to initial coordinates"""
def __init__(self,ps,label,init_coords=None):
self.mdl = ps[0].get_model()
self.model = ps[0].get_model()
self.ps = ps
if init_coords is None:
self.init_coords = [IMP.core.XYZ(p).get_coordinates() for p in self.ps]
else:
self.init_coords = init_coords
self.label = label

@property
@IMP.deprecated_method("3.0", "Model should be accessed with `.model`.")
def mdl(self):
return self.model

def get_output(self):
output = {}
coords = [IMP.core.XYZ(p).get_coordinates() for p in self.ps]
Expand All @@ -590,9 +596,15 @@ def get_output(self):

class TotalScoreOutput(object):
"""A helper output for model evaluation"""
def __init__(self,mdl):
self.mdl = mdl
self.rs = IMP.pmi.tools.get_restraint_set(self.mdl)
def __init__(self,model):
self.model = model
self.rs = IMP.pmi.tools.get_restraint_set(self.model)

@property
@IMP.deprecated_method("3.0", "Model should be accessed with `.model`.")
def mdl(self):
return self.model

def get_output(self):
score = self.rs.evaluate(False)
output = {}
Expand Down
4 changes: 2 additions & 2 deletions pyext/src/io/crosslink.py
Original file line number Diff line number Diff line change
Expand Up @@ -1519,11 +1519,11 @@ def __init__(self,representation=None,
#PMI 1.0 mode
self.mode="pmi1"
self.representation=representation
self.model=self.representation.m
self.model=self.representation.model
elif system is not None:
#PMI 2.0 mode
self.system=system
self.model=self.system.mdl
self.model=self.system.model
self.mode="pmi2"
else:
print("Argument error: please provide either a representation object or a IMP.Hierarchy")
Expand Down
11 changes: 8 additions & 3 deletions pyext/src/io/xltable.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ def __init__(self,contact_threshold):
self._first = True
self.index_dict={}
self.stored_dists={}
self.mdl = IMP.Model()
self.model = IMP.Model()

@property
@IMP.deprecated_method("3.0", "Model should be accessed with `.model`.")
def mdl(self):
return self.model

def _colormap_distance(self, dist, threshold=35, tolerance=0):
if dist < threshold - tolerance:
Expand Down Expand Up @@ -160,7 +165,7 @@ def load_pdb_coordinates(self,pdbfile,chain_to_name_map):
Key: PDB chain ID. Value: Protein name (set in sequence reading)
\note This function returns an error if the sequence for each chain has NOT been read
"""
mh = IMP.atom.read_pdb(pdbfile,self.mdl,IMP.atom.CAlphaPDBSelector())
mh = IMP.atom.read_pdb(pdbfile,self.model,IMP.atom.CAlphaPDBSelector())
total_len = sum(len(self.sequence_dict[s]) for s in self.sequence_dict)
coords = np.ones((total_len,3)) * 1e5 #default to coords "very far away"
prev_stop = 0
Expand Down Expand Up @@ -248,7 +253,7 @@ def load_rmf_coordinates(self,rmf_name,rmf_frame_index, chain_names, nomap=False

def _get_rmf_structure(self,rmf_name,rmf_frame_index):
rh= RMF.open_rmf_file_read_only(rmf_name)
prots=IMP.rmf.create_hierarchies(rh, self.mdl)
prots=IMP.rmf.create_hierarchies(rh, self.model)
IMP.rmf.load_frame(rh, rmf_frame_index)
print("getting coordinates for frame %i rmf file %s" % (rmf_frame_index, rmf_name))
del rh
Expand Down
30 changes: 20 additions & 10 deletions pyext/src/macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,10 +576,10 @@ class BuildSystem(object):
as a dictionary with key = (molecule name), value = IMP.pmi.topology.Molecule
Quick multi-state system:
@code{.python}
mdl = IMP.Model()
model = IMP.Model()
reader1 = IMP.pmi.topology.TopologyReader(tfile1)
reader2 = IMP.pmi.topology.TopologyReader(tfile2)
bs = IMP.pmi.macros.BuildSystem(mdl)
bs = IMP.pmi.macros.BuildSystem(model)
bs.add_state(reader1)
bs.add_state(reader2)
bs.execute_macro() # build everything including degrees of freedom
Expand All @@ -591,27 +591,32 @@ class BuildSystem(object):
as requested.
"""
def __init__(self,
mdl,
model,
sequence_connectivity_scale=4.0,
force_create_gmm_files=False,
resolutions=[1,10]):
"""Constructor
@param mdl An IMP Model
@param model An IMP Model
@param sequence_connectivity_scale For scaling the connectivity restraint
@param force_create_gmm_files If True, will sample and create GMMs
no matter what. If False, will only sample if the
files don't exist. If number of Gaussians is zero, won't
do anything.
@param resolutions The resolutions to build for structured regions
"""
self.mdl = mdl
self.system = IMP.pmi.topology.System(self.mdl)
self.model = model
self.system = IMP.pmi.topology.System(self.model)
self._readers = [] # the TopologyReaders (one per state)
self._domain_res = [] # TempResidues for each domain key=unique name, value=(atomic_res,non_atomic_res).
self._domains = [] # key = domain unique name, value = Component
self.force_create_gmm_files = force_create_gmm_files
self.resolutions = resolutions

@property
@IMP.deprecated_method("3.0", "Model should be accessed with `.model`.")
def mdl(self):
return self.model

def add_state(self,
reader,
keep_chain_id=False, fasta_name_map=None):
Expand Down Expand Up @@ -741,7 +746,7 @@ def execute_macro(self, max_rb_trans=4.0, max_rb_rot=0.04, max_bead_trans=4.0, m
self.root_hier = self.system.build()

print("BuildSystem.execute_macro: setting up degrees of freedom")
self.dof = IMP.pmi.dof.DegreesOfFreedom(self.mdl)
self.dof = IMP.pmi.dof.DegreesOfFreedom(self.model)
for nstate,reader in enumerate(self._readers):
rbs = reader.get_rigid_bodies()
srbs = reader.get_super_rigid_bodies()
Expand Down Expand Up @@ -839,8 +844,8 @@ def __init__(self,
files don't exist. If number of Gaussians is zero, won't
do anything.
"""
self.m = model
self.simo = IMP.pmi.representation.Representation(self.m,
self.model = model
self.simo = IMP.pmi.representation.Representation(self.model,
upperharmonic=True,
disorderedlength=False)

Expand Down Expand Up @@ -939,6 +944,11 @@ def __init__(self,
self.simo.set_floppy_bodies()
self.simo.setup_bonds()

@property
@IMP.deprecated_method("3.0", "Model should be accessed with `.model`.")
def m(self):
return self.model

def get_representation(self):
'''Return the Representation object'''
return self.simo
Expand Down Expand Up @@ -1415,7 +1425,7 @@ def set_coordinates(self,hier_name,xyz_tuple):
def save_rmf(self,rmfname):

o=IMP.pmi.output.Output()
self.simo.m.update()
self.simo.model.update()
o.init_rmf(rmfname,[self.simo.prot])
o.write_rmf(rmfname)
o.close_rmf(rmfname)
Expand Down
2 changes: 1 addition & 1 deletion pyext/src/mmcif.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def __init__(self, state, component, start, end, pdb_offset,
self.state, self.chain, self.hier = state, chain, hier
sel = IMP.atom.NonWaterNonHydrogenPDBSelector() \
& IMP.atom.ChainPDBSelector(chain)
self.starting_hier = IMP.atom.read_pdb(pdbname, state.m, sel)
self.starting_hier = IMP.atom.read_pdb(pdbname, state.model, sel)

rigid = property(lambda self: _get_fragment_is_rigid(self),
lambda self, val: None)
Expand Down
13 changes: 9 additions & 4 deletions pyext/src/plotting/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self,model,selections,cutoff,frequency_cutoff,
"""
import itertools\

self.mdl = model
self.model = model
self.selections = selections
self.contact_counts={}
self.edges=defaultdict(int)
Expand All @@ -47,17 +47,22 @@ def __init__(self,model,selections,cutoff,frequency_cutoff,
self.quantitative_proteomic_data=quantitative_proteomic_data
self.num_rmf=0

@property
@IMP.deprecated_method("3.0", "Model should be accessed with `.model`.")
def mdl(self):
return self.model

def add_rmf(self,rmf_fn,nframe):
"""Add selections from an RMF file"""
print('reading from RMF file',rmf_fn)
rh = RMF.open_rmf_file_read_only(rmf_fn)
prots = IMP.rmf.create_hierarchies(rh, self.mdl)
prots = IMP.rmf.create_hierarchies(rh, self.model)
hier = prots[0]
IMP.rmf.load_frame(rh, RMF.FrameID(0))
ps_per_component=defaultdict(list)
if self.num_rmf==0:
self.size_per_component=defaultdict(int)
self.mdl.update()
self.model.update()

#gathers particles for all components
part_dict = IMP.pmi.analysis.get_particles_at_resolution_one(hier)
Expand All @@ -81,7 +86,7 @@ def add_rmf(self,rmf_fn,nframe):

for n1,name1 in enumerate(self.names):
for name2 in self.names[n1+1:]:
ncontacts = len(self.gcpf.get_close_pairs(self.mdl,
ncontacts = len(self.gcpf.get_close_pairs(self.model,
ps_per_component[name1],
ps_per_component[name2]))
if ncontacts>0:
Expand Down
Loading

0 comments on commit 4adce53

Please sign in to comment.