Exemplo n.º 1
0
def save_model(path, model):
    """Save a full model in directory path (try to create if necessary)."""

    if not isinstance(model, base_objects.Model):
        raise ValueError("Object %s is not a valid Model" % repr(model))

    if not isinstance(path, str):
        raise ValueError("Object %s is not a path string" % repr(path))

    if not os.path.isdir(path):
        logger.warning("Path %s does not exist, try to make it..." % str(path))
        try:
            os.mkdir(path)
        except IOError as xxx_todo_changeme:
            (errno, strerror) = xxx_todo_changeme.args
            logger.error("I/O error (%s): %s" % (errno, strerror))
            return None

    print("Saving particles...", end=' ')
    files.write_to_file(os.path.join(path, 'particles.py'), save_particles,
                        model['particles'])
    print("%i particles saved to %s" %
          (len(model['particles']), os.path.join(path, 'particles.py')))

    print("Saving interactions...", end=' ')
    files.write_to_file(os.path.join(path, 'interactions.py'),
                        save_interactions, model['interactions'])
    print("%i interactions saved to %s" %
          (len(model['interactions']), os.path.join(path, 'interactions.py')))
Exemplo n.º 2
0
def save_to_file(filename, object):
    """Save any Python object to file filename"""

    if not isinstance(filename, str):
        raise SaveObjectError, "filename must be a string"

    files.write_to_file(filename, pickle_object, object)

    return True
Exemplo n.º 3
0
        else:
            fsock.write(str(inter))

    fsock.write("]")


def save_model(path, model):
    """Save a full model in directory path (try to create if necessary)."""

    if not isinstance(model, base_objects.Model):
        raise ValueError, "Object %s is not a valid Model" % repr(model)

    if not isinstance(path, str):
        raise ValueError, "Object %s is not a path string" % repr(path)

    if not os.path.isdir(path):
        logger.warning("Path %s does not exist, try to make it..." % str(path))
        try:
            os.mkdir(path)
        except IOError, (errno, strerror):
            logger.error("I/O error (%s): %s" % (errno, strerror))
            return None

    print "Saving particles...",
    files.write_to_file(os.path.join(path, "particles.py"), save_particles, model["particles"])
    print "%i particles saved to %s" % (len(model["particles"]), os.path.join(path, "particles.py"))

    print "Saving interactions...",
    files.write_to_file(os.path.join(path, "interactions.py"), save_interactions, model["interactions"])
    print "%i interactions saved to %s" % (len(model["interactions"]), os.path.join(path, "interactions.py"))
Exemplo n.º 4
0
    if not isinstance(model, base_objects.Model):
        raise ValueError, \
            "Object %s is not a valid Model" % repr(model)

    if not isinstance(path, str):
        raise ValueError, \
            "Object %s is not a path string" % repr(path)

    if not os.path.isdir(path):
        logger.warning("Path %s does not exist, try to make it..." % str(path))
        try:
            os.mkdir(path)
        except IOError, (errno, strerror):
            logger.error("I/O error (%s): %s" % (errno, strerror))
            return None

    print "Saving particles...",
    files.write_to_file(os.path.join(path, 'particles.py'),
                        save_particles,
                        model['particles'])
    print "%i particles saved to %s" % (len(model['particles']),
                                      os.path.join(path, 'particles.py'))

    print "Saving interactions...",
    files.write_to_file(os.path.join(path, 'interactions.py'),
                        save_interactions,
                        model['interactions'])
    print "%i interactions saved to %s" % (len(model['interactions']),
                                      os.path.join(path, 'interactions.py'))