Esempio n. 1
0
def link_swig(source):
    target = os.path.join("swig")
    tools.mkdir(target)
    for module, g in tools.get_modules(source):
        # they all go in the same dir, so don't remove old links
        tools.link_dir(
            os.path.join(g,
                         "pyext"),
            target,
            match=["*.i"],
            clean=False)
        if os.path.exists(os.path.join(g, "pyext", "include")):
            tools.link_dir(
                os.path.join(g,
                             "pyext",
                             "include"),
                target,
                match=["*.i"],
                clean=False)
        tools.link(
            os.path.join(
                g,
                "pyext",
                "swig.i-in"),
            os.path.join(
                target,
                "IMP_%s.impl.i" %
                module))
Esempio n. 2
0
def run_swig(outputdir, options):
    args = [options.swig]
    args.append("-castmode")
    args.extend(["-interface", "_IMP_%s" % options.module])
    args.append("-DPySwigIterator=IMP_%s_PySwigIterator" %
                options.module.upper())
    args.append("-DSwigPyIterator=IMP_%s_SwigPyIterator" %
                options.module.upper())
    args.append("-python")
    args.append("-c++")
    args.append("-naturalvar")
    args.append("-modern")
    args.append("-fvirtual")
    args.append("-Wextra")
    args.append("-I" + os.path.join("..", "..", "include"))
    args.append("-I" + os.path.join("..", "..", "swig"))
    args.extend(["-oh", "wrap.h-in"])
    args.extend(["-o", "wrap.cpp-in"])
    if options.module == "base":
        args.append("-DIMP_SWIG_BASE")
    for p in options.swigpath:
        args.append("-I%s" % tools.from_cmake_path(p))
    for p in options.includepath:
        args.append("-I%s" % tools.from_cmake_path(p))
    args.append(os.path.abspath("./swig/IMP_%s.i" % options.module))

    ret = tools.run_subprocess(args, cwd=outputdir)
    if len(
            open("src/%s_swig/IMP.%s.py" %
                 (options.module, options.module), "r").read()) < 10:
        raise IOError("Empty swig wrapper file")
    tools.link("src/%s_swig/IMP.%s.py" % (options.module, options.module),
               "lib/IMP/%s/__init__.py" % options.module)
Esempio n. 3
0
def run_swig(outputdir, options):
    args = [options.swig]
    args.append("-castmode")
    args.extend(["-interface", "_IMP_%s" % options.module])
    args.append(
        "-DPySwigIterator=IMP_%s_PySwigIterator" %
        options.module.upper())
    args.append(
        "-DSwigPyIterator=IMP_%s_SwigPyIterator" %
        options.module.upper())
    args.append("-python")
    args.append("-c++")
    args.append("-naturalvar")
    args.append("-modern")
    args.append("-fvirtual")
    args.append("-Wextra")
    args.append("-I" + os.path.join("..", "..", "include"))
    args.append("-I" + os.path.join("..", "..", "swig"))
    args.extend(["-oh", "wrap.h-in"])
    args.extend(["-o", "wrap.cpp-in"])
    if options.module == "base":
        args.append("-DIMP_SWIG_BASE")
    for p in options.swigpath:
        args.append("-I%s" % tools.from_cmake_path(p))
    for p in options.includepath:
        args.append("-I%s" % tools.from_cmake_path(p))
    args.append(os.path.abspath("./swig/IMP_%s.i" % options.module))

    ret = tools.run_subprocess(args, cwd=outputdir)
    if len(open("src/%s_swig/IMP.%s.py" % (options.module, options.module), "r").read()) < 10:
        raise IOError("Empty swig wrapper file")
    tools.link("src/%s_swig/IMP.%s.py" % (options.module, options.module),
               "lib/IMP/%s/__init__.py" % options.module)
Esempio n. 4
0
def main():
    alias_headers(
        os.path.join('include', 'IMP'), os.path.join('include', 'IMP',
                                                     'kernel'),
        os.path.join('include', 'IMP', 'base'), 'IMP', [
            'AttributeOptimizer.h', 'base_types.h', 'Configuration.h',
            'ConfigurationSet.h', 'constants.h', 'Constraint.h',
            'container_base.h', 'container_macros.h', 'Decorator.h',
            'decorator_macros.h', 'dependency_graph.h',
            'DerivativeAccumulator.h', 'doxygen.h', 'FloatIndex.h',
            'functor.h', 'generic.h', 'input_output.h', 'io.h', 'Key.h',
            'macros.h', 'Model.h', 'ModelObject.h', 'model_object_helpers.h',
            'Optimizer.h', 'OptimizerState.h', 'Particle.h',
            'particle_index.h', 'ParticleTuple.h', 'python_only.h',
            'Refiner.h', 'Restraint.h', 'RestraintSet.h', 'Sampler.h',
            'scoped.h', 'ScoreAccumulator.h', 'ScoreState.h',
            'ScoringFunction.h', 'UnaryFunction.h', 'Undecorator.h',
            'utility.h'
        ], {'base_utility.h': 'utility.h'})
    alias_headers(
        os.path.join('include', 'IMP', 'internal'),
        os.path.join('include', 'IMP', 'kernel', 'internal'),
        os.path.join('include', 'IMP', 'base', 'internal'), 'IMP/internal', [
            'AccumulatorScoreModifier.h', 'AttributeTable.h',
            'attribute_tables.h', 'constants.h', 'ContainerConstraint.h',
            'container_helpers.h', 'ContainerRestraint.h',
            'ContainerScoreState.h', 'create_decomposition.h',
            'DynamicListContainer.h', 'evaluate_utility.h',
            'ExponentialNumber.h', 'functors.h', 'graph_utility.h',
            'IndexingIterator.h', 'input_output_exception.h', 'key_helpers.h',
            'ListLikeContainer.h', 'NestedIterator.h', 'pdb.h',
            'PrefixStream.h', 'restraint_evaluation.h',
            'RestraintsScoringFunction.h', 'scoring_functions.h', 'static.h',
            'StaticListContainer.h', 'swig.h', 'swig_helpers.h',
            'TupleConstraint.h', 'TupleRestraint.h', 'Unit.h', 'units.h',
            'utility.h'
        ], {
            'base_graph_utility.h': 'graph_utility.h',
            'base_static.h': 'static.h',
            'swig_base.h': 'swig.h',
            'swig_helpers_base.h': 'swig_helpers.h'
        })
    tools.rewrite(os.path.join('include', 'IMP', 'base', 'base_config.h'),
                  get_header_contents('IMP', 'kernel_config.h'))
    tools.link(os.path.join('include', 'IMP.h'),
               os.path.join('include', 'IMP', 'kernel.h'))
    tools.link(os.path.join('include', 'IMP.h'),
               os.path.join('include', 'IMP', 'base.h'))
    for mod in ('base', 'kernel'):
        subdir = os.path.join('lib', 'IMP', mod)
        if not os.path.exists(subdir):
            os.mkdir(subdir)
        pymod = os.path.join(subdir, '__init__.py')
        with open(pymod, 'w') as fh:
            fh.write("""import sys
sys.stderr.write('IMP.%s is deprecated - use "import IMP" instead\\n')
from IMP import *
""" % mod)
Esempio n. 5
0
def main():
    alias_headers(os.path.join('include', 'IMP'),
                  os.path.join('include', 'IMP', 'kernel'),
                  os.path.join('include', 'IMP', 'base'),
                  'IMP', [ 'AttributeOptimizer.h', 'base_types.h',
         'Configuration.h', 'ConfigurationSet.h', 'constants.h',
         'Constraint.h', 'container_base.h', 'container_macros.h',
         'Decorator.h', 'decorator_macros.h', 'dependency_graph.h',
         'DerivativeAccumulator.h', 'doxygen.h', 'FloatIndex.h',
         'functor.h', 'generic.h', 'input_output.h', 'io.h', 'Key.h',
         'macros.h', 'Model.h', 'ModelObject.h', 'model_object_helpers.h',
         'Optimizer.h', 'OptimizerState.h', 'Particle.h', 'particle_index.h',
         'ParticleTuple.h', 'python_only.h', 'Refiner.h', 'Restraint.h',
         'RestraintSet.h', 'Sampler.h', 'scoped.h', 'ScoreAccumulator.h',
         'ScoreState.h', 'ScoringFunction.h', 'UnaryFunction.h',
         'Undecorator.h', 'utility.h' ],
         {'base_utility.h': 'utility.h' })
    alias_headers(os.path.join('include', 'IMP', 'internal'),
                  os.path.join('include', 'IMP', 'kernel', 'internal'),
                  os.path.join('include', 'IMP', 'base', 'internal'),
                 'IMP/internal', [ 'AccumulatorScoreModifier.h',
         'AttributeTable.h', 'attribute_tables.h', 'constants.h',
         'ContainerConstraint.h', 'container_helpers.h', 'ContainerRestraint.h',
         'ContainerScoreState.h', 'create_decomposition.h',
         'DynamicListContainer.h', 'evaluate_utility.h', 'ExponentialNumber.h',
         'functors.h', 'graph_utility.h', 'IndexingIterator.h',
         'input_output_exception.h', 'key_helpers.h', 'ListLikeContainer.h',
         'NestedIterator.h', 'pdb.h', 'PrefixStream.h',
         'restraint_evaluation.h', 'RestraintsScoringFunction.h',
         'scoring_functions.h', 'static.h', 'StaticListContainer.h', 'swig.h',
         'swig_helpers.h', 'TupleConstraint.h', 'TupleRestraint.h',
         'Unit.h', 'units.h', 'utility.h' ],
         {'base_graph_utility.h': 'graph_utility.h',
          'base_static.h': 'static.h',
          'swig_base.h': 'swig.h',
          'swig_helpers_base.h': 'swig_helpers.h'})
    tools.rewrite(os.path.join('include', 'IMP', 'base', 'base_config.h'),
                  get_header_contents('IMP', 'kernel_config.h'))
    tools.link(os.path.join('include', 'IMP.h'),
               os.path.join('include', 'IMP', 'kernel.h'))
    tools.link(os.path.join('include', 'IMP.h'),
               os.path.join('include', 'IMP', 'base.h'))
    for mod in ('base', 'kernel'):
        subdir = os.path.join('lib', 'IMP', mod)
        if not os.path.exists(subdir):
            os.mkdir(subdir)
        pymod = os.path.join(subdir, '__init__.py')
        with open(pymod, 'w') as fh:
            fh.write("""import sys
sys.stderr.write('IMP.%s is deprecated - use "import IMP" instead\\n')
from IMP import *
""" % mod)
Esempio n. 6
0
def link_swig(source):
    target = os.path.join("swig")
    tools.mkdir(target)
    for module, g in tools.get_modules(source):
        # they all go in the same dir, so don't remove old links
        tools.link_dir(os.path.join(g, "pyext"),
                       target,
                       match=["*.i"],
                       clean=False)
        if os.path.exists(os.path.join(g, "pyext", "include")):
            tools.link_dir(os.path.join(g, "pyext", "include"),
                           target,
                           match=["*.i"],
                           clean=False)
        tools.link(os.path.join(g, "pyext", "swig.i-in"),
                   os.path.join(target, "IMP_%s.impl.i" % module))
Esempio n. 7
0
def main():
    name_template = "simple_graph{0}"
    simple_parser = argparse.ArgumentParser(
            formatter_class=argparse.RawTextHelpFormatter,
            description="""Create a simple graph""",
            epilog=textwrap.dedent("""
            The test set is generated in the following way:
            1. shuffles vertices 
            Example:
                num_vertices = 8
                [0, 1, 2, 3, 4, 5, 6, 7] -> 
                [3, 4, 1, 2, 6, 0, 7, 5]

            2. splits them according to 'd' ...
                first method
                d[0] = 2, d[1] = 3, d[2] = 3
                a = [3, 4]
                b = [1, 2, 6]
                c = [7, 5, 0]

                d[0] = 0.25, d[1] = 0.5 (implicitly d[2] = 0.25)
                a = [3, 4]
                b = [1, 2, 6]
                c = [7, 5, 0]

            3. links them 
                edges[0] = [(3,4)]
                edges[1] = [(1,2), (2,6)]
                edges[2] = [(7,5), (5,0)]

            4. adds e additional edges
                first method
                e = 0 1 1
                edges[1] = [(1,2), (2,6), (1,6)]
                edges[2] = [(7,5), (5,0), (7,0)]
                second method
                2 0 0.5 
                edges[1] = [(1,2), (2,6), (1,6)]
                edges[2] = [(7,5), (5,0), (7,0)]

            5. Generates two files
                c = 1, 6 [ vertex intial and vertex final ]
                simple_graphx.in 
                x increments if there already exists prior .in
                Also order of edges are shuffled
                Also all values are increased by one as vertices start from 1
                according to course specification
                simple_graph2.in [ if for example simple_graph1.in already exists ]
                8 10 [num vertices, num edges]
                2 3
                2 7
                ...
                4 5
                1 6 [ vertices you want to go from and to specified by -c can be blank]
                test number for .group will match test number for .in
                will overwrite any .group with same number
                simple_graph2.group 
                3, 4
                1, 2, 6
                7, 5, 0
            """)
            )
    graph_parser(simple_parser)
    simple_parser.add_argument(
            '-c', 
            type=int, 
            help="inital and destination vertex",
            nargs='*'
            )
    simple_parser.add_argument(
            '-s',
            "--show",
            help=textwrap.dedent("""
            If included creates image using graphviz
            """.format(name_template)),
            action="store_true"
            )
    args = simple_parser.parse_args()
    num_vertices, ranges, vertices, split_vertices, additional_edges = create_graph(args)
    edges = link(split_vertices, linker)
    add_extra_edges(edges, split_vertices, additional_edges)
    edges_str = edges_to_str(edges)
    in_str = first_line(num_vertices, edges) + edges_str 
    if args.c is not None:
        if len(args.c) != 2:
            raise ValueError(
                    "num -c args is {0}, should be  2".format(len(args.c)))
        in_str += last_line(args.c)
    split_vertices_str = split_vertices_to_str(split_vertices)
    i = write_in_and_group(in_str, split_vertices_str, file_dir, args.o, name_template)
    flat_edges = [ list(edge) for edgesli in edges for edge in edgesli ]
    s = bool(args.show)
    if s:
        image_filename = name_template.format(i) + ".png"
        dot_str = to_dot(flat_edges, directed=False)
        create_image(dot_str, image_filename)