On the following figure, we see an XML representation of the molecular hierarchy.
<!-- File: eg1_representation.xml --> <Representation> <Protein id="Protein1"> <Chain filename="data/protein1.pdb" selector="CAlpha"/> <Chain> <Fragment> <GeometricShapeRep total_residue="10"> <Sphere/> </GeometricShapeRep> </Fragment> </Chain> </Protein> <Protein id="Protein2"> <Chain filename="data/protein2.pdb"/> </Protein> </Representation>
Each level of molecular hierarchy corresponds to an XML tag. Each tag can have optional attributes. In this example, each protein has a unique id. Protein1 has 2 chains. The first chain is constructed from the PDB file using IMP::atom::CAlphaSelector. The second chain is represented by a sphere fragment that is big enough to contain 10 residues. Protein2 is constructed using the default selector, IMP::atom::NonWaterNonHydrogenSelector.
The following figure shows the definition of the restraint.
<!-- File: eg1_restraint.xml --> <RestraintSet> <Pulldown> <Restraint> <Particle id="Protein1"/> <Particle id="Protein2"/> </Restraint> </Pulldown> </RestraintSet>
The pulldown restraint is applied to Protein1 and Protein2.
The following Python script demonstrates the process of loading our data into IMP
model.
#-- File: basic_setup.py --# import IMP import IMP.restrainer # Load molecular hierarchy definition rep_parser = IMP.restrainer.XMLRepresentation( IMP.restrainer.get_example_path('input/eg1_representation.xml')) representation = rep_parser.run() # Load the restraint set restraint_parser = IMP.restrainer.XMLRestraint( IMP.restrainer.get_example_path('input/eg1_restraint.xml')) restraint = restraint_parser.run() # Place representation into IMP model model = representation.to_model() # Place restraint into IMP model restraint.add_to_representation(representation) ###=======================================================================### # At this point all data from XML files have been placed into the model. # Now it is possible to perform various operations on the IMP model. ###=======================================================================### model.show() model.evaluate(False)
<!-- File: eg2_representation.xml --> <Representation> <Protein id="Protein1"><Chain filename="data/protein1.pdb"/></Protein> <Protein id="Protein2"><Chain filename="data/protein2.pdb"/></Protein> <Protein id="Protein3"><Chain filename="data/protein3.pdb"/></Protein> <Protein id="Protein4"><Chain filename="data/protein4.pdb"/></Protein> <Protein id="Protein5"><Chain filename="data/protein5.pdb"/></Protein> </Representation>
From restrainer's point of view, a Rigid Body is a special form of restraint. Therefore, to make some parts of the hierarchy rigid, suitable rigid body declarations should be placed in the restraint XML file.
<!-- File: eg2_restraint.xml --> <RestraintSet> <RigidBody> <Restraint><Particle id="Protein1"/></Restraint> <Restraint><Particle id="Protein2"/></Restraint> <Restraint><Particle id="Protein3"/></Restraint> <Restraint><Particle id="Protein4"/></Restraint> <Restraint><Particle id="Protein5"/></Restraint> </RigidBody> <ExcludedVolume> <Restraint> <Particle id="Protein1"/> <Particle id="Protein2"/> <Particle id="Protein3"/> <Particle id="Protein4"/> <Particle id="Protein5"/> </Restraint> </ExcludedVolume> <Y2H> <Restraint> <Particle id="Protein1"/> <Particle id="Protein2"/> <Particle id="Protein3"/> </Restraint> <Restraint> <Particle id="Protein4"/> <Particle id="Protein5"/> </Restraint> </Y2H> </RestraintSet>
#-- File: rigid_body_and_excluded_volume_restraint.py --# import IMP import IMP.restrainer # Load molecular hierarchy definition rep_parser = IMP.restrainer.XMLRepresentation( IMP.restrainer.get_example_path('input/eg2_representation.xml')) representation = rep_parser.run() # Load the restraint set restraint_parser = IMP.restrainer.XMLRestraint( IMP.restrainer.get_example_path('input/eg2_restraint.xml')) restraint = restraint_parser.run() # Place representation into IMP model model = representation.to_model() # Place restraint into IMP model restraint.add_to_representation(representation) ###=======================================================================### # At this point all data from XML files have been placed into the model. # Now it is possible to perform various operations on the IMP model. ###=======================================================================### # Find the IMP data structure with the given id protein1_hierarchy = representation.get_imp_hierarchy_by_id('Protein1') # Get root hierarchy root_hierarchy = representation.get_root_imp_hierarchy() # Get the rigid body with the given id protein1_rb = restraint.get_rigid_body_by_id ("Protein1") # Get all rigid bodies rbs = restraint.get_all_rigid_bodies() # Define transformation ub = IMP.algebra.Vector3D(-50.0,-50.0,-50.0) lb = IMP.algebra.Vector3D( 50.0, 50.0, 50.0) bb = IMP.algebra.BoundingBox3D(ub, lb) translation = IMP.algebra.get_random_vector_in(bb) rotation = IMP.algebra.get_random_rotation_3d() transformation = IMP.algebra.Transformation3D(rotation, translation) # Perform geometric transformations on the Protein1 rigid body protein1_rb.set_transformation(transformation) protein1_rb.show()
<!-- File: em_representation.xml --> <Representation> <Protein id="Protein1"> <Chain> <Fragment id="frag1"> <GeometricShapeRep> <Sphere radius="1.0" weight="1.0"> <InitialPosition optimize="1" x="12.0" y="12.0" z="12.0"/> </Sphere> </GeometricShapeRep> </Fragment> <Fragment id="frag2"> <GeometricShapeRep> <Sphere radius="1.0" weight="1.0"> <InitialPosition optimize="1" x="15.0" y="6.0" z="6.0"/> </Sphere> </GeometricShapeRep> </Fragment> <Fragment id="frag3"> <GeometricShapeRep> <Sphere radius="1.0" weight="1.0"> <InitialPosition optimize="1" x="6.0" y="15.0" z="15.0"/> </Sphere> </GeometricShapeRep> </Fragment> </Chain> </Protein> </Representation>
<!-- File: em_restraint.xml --> <RestraintSet> <EM> <Restraint name="em_restraint" density_filename="data/in.mrc" spacing="1.0" resolution="3.0" xorigin="-6.0" yorigin="-6.0" zorigin="-6.0"> <Particle id="frag1"/> <Particle id="frag2"/> <Particle id="frag3"/> </Restraint> </EM> </RestraintSet>
#-- File: em_restraint.py --# import IMP import IMP.restrainer # Load molecular hierarchy definition rep_parser = IMP.restrainer.XMLRepresentation( IMP.restrainer.get_example_path('input/em_representation.xml')) representation = rep_parser.run() # Load the restraint set restraint_parser = IMP.restrainer.XMLRestraint( IMP.restrainer.get_example_path('input/em_restraint.xml')) restraint = restraint_parser.run() # Place representation into IMP model model = representation.to_model() # Place restraint into IMP model restraint.add_to_representation(representation) ###=======================================================================### # At this point all data from XML files have been placed into the model. # Now it is possible to perform various operations on the IMP model. ###=======================================================================### # Get restraint by name r = restraint.get_restraint_by_name('em_restraint') # Get EM density map header from the restraint dmap_header = r.dmap_header # Get IMP::em::FitRestraint fit_restraint = r.imp_restraint fit_restraint.evaluate(False)
<!-- File: saxs_representation.xml --> <Representation> <Protein id="6lyz"> <Chain filename="data/6lyz.pdb" selector="NonWaterNonHydrogen"/> </Protein> </Representation>
<!-- File: saxs_restraint.xml --> <RestraintSet> <SAXS> <Restraint name="saxs_restraint" profile_filename="data/lyzexp.dat"> <Particle id="6lyz"></Particle> </Restraint> </SAXS> </RestraintSet>
#-- File: saxs_restraint.py --# import IMP import IMP.restrainer # Load molecular hierarchy definition rep_parser = IMP.restrainer.XMLRepresentation( IMP.restrainer.get_example_path('input/saxs_representation.xml')) representation = rep_parser.run() # Load the restraint set restraint_parser = IMP.restrainer.XMLRestraint( IMP.restrainer.get_example_path('input/saxs_restraint.xml')) restraint = restraint_parser.run() # Place representation into IMP model model = representation.to_model() # Place restraint into IMP model restraint.add_to_representation(representation) ###=======================================================================### # At this point all data from XML files have been placed into the model. # Now it is possible to perform various operations on the IMP model. ###=======================================================================### # Get restraint by name r = restraint.get_restraint_by_name('saxs_restraint') # Get IMP::saxs::Restraint saxs_restraint = r.imp_restraint saxs_restraint.evaluate(False)
This example shows how to color the representation components and output display file in chimera format.
<!-- File: display_representation.xml --> <Representation> <Protein id="Protein1"> <Chain id="Chain1" filename="data/6lyz.pdb"> <Fragment id="Frag1"><AtomicRep start_residue="1" end_residue="10"/></Fragment> <Fragment id="Frag2"><AtomicRep start_residue="11" end_residue="20"/></Fragment> <Fragment id="Frag3"><AtomicRep start_residue="21" end_residue="30"/></Fragment> <Fragment id="Frag4"><AtomicRep start_residue="31" end_residue="40"/></Fragment> </Chain> </Protein> </Representation>
<!-- File: pdb_display.xml --> <Display> <Protein id="Protein1"> <Chain id="Chain1"><Color r="1" g="1" b="1"/> <Fragment id="Frag1"><Color r="0" g="1" b="1"/></Fragment> <Fragment id="Frag2"><Color r="1" g="0" b="1"/></Fragment> <Fragment id="Frag3"><Color r="1" g="1" b="0"/></Fragment> <Fragment id="Frag4"><Color r="1" g="0" b="0"/></Fragment> </Chain> </Protein> </Display>
Loading a display XML file is similar to loading the representation and restraint XML definitions. Only particles mentioned in the display XML file will be present (this is useful if we only want to display some portion of an hierarchy). The arguments to the create_log are the representation and the file name template (this '%03d' will be replaced by consecutive numbers if we do optimization). This log is intended to be added to an optimization by performing: optimization.add_optimizer_state(log)
#-- File: basic_display.py --# import IMP import IMP.restrainer # Load molecular hierarchy definition rep_parser = IMP.restrainer.XMLRepresentation( IMP.restrainer.get_example_path('input/display_representation.xml')) representation = rep_parser.run() # Load color definition display_parser = IMP.restrainer.XMLDisplay( IMP.restrainer.get_example_path('input/pdb_display.xml')) display = display_parser.run() # Place representation into IMP model model = representation.to_model() # Write initial display in Chimera format log = display.create_log(representation, 'pdb_log_%03d.py') log.write('initial_display_in_chimera.py') ###=======================================================================### # At this point all data from XML files have been placed into the model. # Now it is possible to perform various operations on the IMP model. ###=======================================================================### model.show() model.evaluate(False)