How to use the lightdock.error.lightdock_errors.LightDockError function in lightdock

To help you get started, we’ve selected a few lightdock examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github brianjimenez / lightdock / lightdock / error / lightdock_errors.py View on Github external
"""Reading potential file error"""
    pass


class ScoringFunctionError(LightDockError):
    """Error in the scoring function drivers"""
    pass


class NotSupportedInScoringError(LightDockError):
    """Error to be raised when an atom or residue type is
    not supported by the scoring function"""
    pass


class NormalModesCalculationError(LightDockError):
    """Error in normal modes calculation"""
    pass
github brianjimenez / lightdock / lightdock / error / lightdock_errors.py View on Github external
class LightDockError(Exception):
    """LightDock exception base class"""
    def __init__(self, cause):
        self.cause = cause

    def __str__(self):
        representation = "[%s] %s" % (self.__class__.__name__, self.cause)
        return representation


class LightDockWarning(LightDockError):
    """Custom error class intented only for warnings to be notified, not to fail"""
    pass


class RandomNumberError(LightDockError):
    """Custom RandomNumber exception"""
    pass


class GSOError(LightDockError):
    """Custom GSO exception"""
    pass


class GSOParameteresError(GSOError):
    """Custom GSOParameteres exception"""
    pass


class GSOCoordinatesError(GSOError):
    """Custom error for CoordinatesFileReader class"""
github brianjimenez / lightdock / lightdock / prep / simulation.py View on Github external
def prepare_results_environment(swarms=10):
    """Prepares the folder structure required by the simulation"""
    log.info("Preparing environment")
    for id_swarm in range(swarms):
        saving_path = "%s%d" % (DEFAULT_SWARM_FOLDER, id_swarm)
        if os.path.isdir(saving_path):
            raise LightDockError("Simulation folder %s already exists" % saving_path)
        else:
            os.mkdir(saving_path)
    log.info("Done.")
github brianjimenez / lightdock / lightdock / error / lightdock_errors.py View on Github external
def __str__(self):
        representation = "[%s] %s" % (self.__class__.__name__, self.cause)
        return representation


class LightDockWarning(LightDockError):
    """Custom error class intented only for warnings to be notified, not to fail"""
    pass


class RandomNumberError(LightDockError):
    """Custom RandomNumber exception"""
    pass


class GSOError(LightDockError):
    """Custom GSO exception"""
    pass


class GSOParameteresError(GSOError):
    """Custom GSOParameteres exception"""
    pass


class GSOCoordinatesError(GSOError):
    """Custom error for CoordinatesFileReader class"""
    pass


class StructureError(LightDockError):
    """General structure error"""
github brianjimenez / lightdock / lightdock / prep / simulation.py View on Github external
rec_translation, lig_translation,
                                                        init_folder,
                                                        ftdock_file, use_anm,
                                                        anm_seed, anm_rec, anm_lig,
                                                        is_membrane)
        log.info("Generated %d positions files" % len(starting_points_files))
    else:
        if receptor_restraints:
            log.warning("Folder %s already exists and restraints apply. Check for consistency, possible error!" % init_folder)
        else:
            log.warning("Folder %s already exists, skipping calculation" % init_folder)

        pattern = os.path.join(DEFAULT_POSITIONS_FOLDER, "%s*.dat" % DEFAULT_STARTING_PREFIX)
        starting_points_files = glob.glob(pattern)
        if len(starting_points_files) != swarms:
            raise LightDockError("The number of initial positions files does not correspond with the number of swarms")
        for starting_point_file in starting_points_files:
            if not check_starting_file(starting_point_file, glowworms, use_anm, anm_rec, anm_lig):
                raise LightDockError("Error reading starting coordinates from file %s" % starting_point_file)
    log.info("Done.")
    return starting_points_files
github brianjimenez / lightdock / lightdock / prep / simulation.py View on Github external
def load_starting_positions(swarms, glowworms, use_anm, anm_rec=DEFAULT_NMODES_REC, anm_lig=DEFAULT_NMODES_LIG):
    """Gets the list of starting positions of this simulation"""
    pattern = os.path.join(DEFAULT_POSITIONS_FOLDER, "%s*.dat" % DEFAULT_STARTING_PREFIX)
    starting_points_files = sorted(glob.glob(pattern))
    if len(starting_points_files) != swarms:
        raise LightDockError("The number of initial positions files does not correspond with the number of swarms")
    for swarm_id in range(len(starting_points_files)):
        starting_point_file = os.path.join(DEFAULT_POSITIONS_FOLDER, "%s_%d.dat" % (DEFAULT_STARTING_PREFIX, swarm_id))
        if not check_starting_file(starting_point_file, glowworms, use_anm, anm_rec, anm_lig):
            raise LightDockError("Error reading starting coordinates from file %s" % starting_point_file)
    return starting_points_files
github brianjimenez / lightdock / lightdock / prep / simulation.py View on Github external
def create_simulation_info_file(args, path='.', file_name=DEFAULT_LIGHTDOCK_INFO):
    """Creates a simulation file from which recover from in a new simulation"""
    # Create the simulation info file. If it exists, includes a number
    # in the extension to avoid collision
    output_file_name = os.path.join(path, file_name)
    if os.path.isfile(output_file_name):
        original_file_name = output_file_name
        i = 1
        while os.path.isfile(output_file_name) and i < 255:
            output_file_name = "%s.%d" % (original_file_name, i)
            i += 1
        if i == 255:
            raise LightDockError('Too many simulation files')

    # Data to store
    now = time.strftime("%Y-%m-%d %H:%M:%S")
    data = {'start_time': now}
    data.update(vars(args))

    # Store the data in the file sorted alphabetically
    with open(output_file_name, 'w') as fp:
        json.dump(vars(args), fp, indent=4, sort_keys=True)

    return output_file_name
github brianjimenez / lightdock / bin / post / lgd_generate_glowworm_positions.py View on Github external
if input_file_extension == DEFAULT_LIST_EXTENSION:
        with open(input_file) as input_lines:
            for line in input_lines:
                file_name = line.rstrip(os.linesep)
                lightdock_structure = os.path.join(os.path.dirname(file_name),
                                                   DEFAULT_LIGHTDOCK_PREFIX % os.path.basename(file_name))
                if os.path.exists(lightdock_structure):
                    file_names.append(lightdock_structure)
    else:
        file_name = input_file
        lightdock_structure = os.path.join(os.path.dirname(file_name),
                                           DEFAULT_LIGHTDOCK_PREFIX % os.path.basename(file_name))
        if os.path.exists(lightdock_structure):
            file_names.append(lightdock_structure)
        else:
            raise LightDockError('Structure file %s not found' % lightdock_structure)
    return file_names
github brianjimenez / lightdock / lightdock / error / lightdock_errors.py View on Github external
class GSOError(LightDockError):
    """Custom GSO exception"""
    pass


class GSOParameteresError(GSOError):
    """Custom GSOParameteres exception"""
    pass


class GSOCoordinatesError(GSOError):
    """Custom error for CoordinatesFileReader class"""
    pass


class StructureError(LightDockError):
    """General structure error"""
    pass


class BackboneError(StructureError):
    """General structure error"""
    pass


class SideChainError(StructureError):
    """General structure error"""
    pass


class ResidueNonStandardError(StructureError):
    """General structure error"""
github brianjimenez / lightdock / bin / simulation / lightdock_setup.py View on Github external
# Parse restraints if any:
        receptor_restraints = ligand_restraints = None
        if args.restraints:
            log.info("Reading restraints from %s" % args.restraints)
            restraints = parse_restraints_file(args.restraints)

            # Calculate number of restraints in order to check them
            num_rec_active = len(restraints['receptor']['active'])
            num_rec_passive = len(restraints['receptor']['passive'])
            num_lig_active = len(restraints['ligand']['active'])
            num_lig_passive = len(restraints['ligand']['passive'])

            # Complain if not a single restraint has been defined, but restraints are enabled
            if not num_rec_active and not num_rec_passive and not num_lig_active and not num_lig_passive:
                raise LightDockError("Restraints file specified, but not a single restraint found")

            # Check if restraints correspond with real residues
            receptor_restraints = get_restraints(receptor, restraints['receptor'])
            args.receptor_restraints = restraints['receptor']
            ligand_restraints = get_restraints(ligand, restraints['ligand'])
            args.ligand_restraints = restraints['ligand']

            log.info("Number of receptor restraints is: %d (active), %d (passive)" % (num_rec_active, num_rec_passive))
            log.info("Number of ligand restraints is: %d (active), %d (passive)" % (num_lig_active, num_lig_passive))

        rec_restraints = None
        try:
            rec_restraints = receptor_restraints['active'] + receptor_restraints['passive']
        except:
            pass