Пример #1
0
    def _run_script_on_coder(self, base_values):
        self.output_dataset_coder_path = self.output_dataset_path + '/' + self.coder_dictionary['o_folder']
        create_folder(self.output_dataset_coder_path)

        coder_name = self.coder_dictionary['name']
        if coder_name == 'CoderBase':
            base_values = self._run_script_on_base_coder(base_values)
        else:
            self._run_script_of_other_coders(base_values)
        return base_values
Пример #2
0
    def _run_script_on_dataset(self, dataset_dictionary):
        self.input_path = self.DATASETS_PATH + dataset_dictionary['folder']
        logger_name = dataset_dictionary['name'].lower() + '.log'
        logger_filename = self.output_path + logger_name
        self.logger = setup_logger(logger_name, logger_filename)

        self.output_dataset_path = self.output_path + dataset_dictionary['o_folder']
        create_folder(self.output_dataset_path)
        dataset_name = dataset_dictionary['name']

        for file_index, self.input_filename in enumerate(ExperimentsUtils.dataset_csv_filenames(dataset_name)):
            self.row = [dataset_name] if file_index == 0 else [None]
            self._run_script_on_file(file_index)
def separate_ligands(file_path, folder):
    """
    Separate .mae file into entries.

    :param str file_path: .mae file to separate
    :param str folder: workspace folder to save separated files

    :var str intro: required intro part to write into each new .mae file
    :var list parts: sections of the file

    :return int error_code:
        1: No input provided
        2: File doesn't exist
    :return list or None titles_file: returns files paths in the same order as in the input (file_path)
    """

    try:
        file = open(file_path).read()
    except TypeError:
        print("No input file!")
        return 1, None
    except FileNotFoundError:
        print("No such file: %s" % file_path)
        return 2, None

    create_folder(folder)  # utils.py

    parts = file.split(' } \n} \n')  # Splits .mae file into separate sections

    intro = parts[0].split(
        "} \n\n"
    )[0]  # First section will also contain intro part, here we also separate it.
    intro = "".join([intro, "} \n"])

    parts[0] = parts[0].split("} \n\n")[1]

    titles_file = []

    for i in range(len(parts) - 1):
        title0 = parts[i].split(" :::")[1].split('\n')[1].strip(
        )  # Suitable descriptor for file name can be found here.
        title1 = title0.split(":")[-1]
        titles_file.append(title1)

        out = open("%s/%s.mae" % (folder, title1),
                   'w')  # Saving single section with intro.
        out.write(intro)
        out.write(parts[i])
        out.write(" } \n} \n")
        out.close()
    return 0, titles_file
    def main():
        """
        Main function. Creates Maestro script.
        """

        # Storing paths to files and normalizing them
        GLOBAL_VARIABLES = CONFIGURE(args.update)  # utils.py
        workspace_folder = os.path.abspath("./workspace")
        docking_folder = os.path.abspath("./docking")
        docking_file = os.path.abspath(args.docking)
        ligands_folder = os.path.abspath("./ligands")

        create_folder(workspace_folder, True)  # utils.py

        unzipped = unzip(docking_file, workspace_folder)  # SMARTS_extract.py

        SMARTS = SMARTS_extract(required, unzipped, docking_folder,
                                workspace_folder)  # SMARTS_extract.py

        os.system("%s %s/run pv_convert.py -mode merge %s" %
                  (GLOBAL_VARIABLES[1], GLOBAL_VARIABLES[0], unzipped))

        input_file = ""
        for i in os.listdir(workspace_folder):
            if unzipped.rstrip(
                    "_pv.mae"
            ) in i and "out_complex" in i and "maegz" not in i:
                input_file = "/".join([workspace_folder, i])
                break

        titles_file = []
        if input_file:
            error_code, titles_file = separate_ligands(
                input_file, ligands_folder)  # file_separate.py
            if error_code != 0:
                parser.print_help()
                exit(error_code)
        else:
            print("File not found - complex.")
            exit()

        maestro_writer(args.output, args.crystal, input_file, titles_file,
                       SMARTS)  # utils.py

        if args.remove:
            paths = [ligands_folder, docking_folder,
                     workspace_folder]  # Folders to clean.
            cleanup(paths)  # utils.py
Пример #5
0
def update_pkg(pkg_name,
               target_folder,
               src_folder=None,
               create_bkup=False,
               compile=True):
    """install or update a packagein a specific folder
    expect to download and extract a wheel file e.g. "yt_dlp-2020.10.24.post6-py2.py3-none-any.whl", which in fact
    is a zip file

    Args:
        pkg_name (str): package name
        url (str): download url (for a wheel file)
        target_folder (str): target installation folder for the package
        src_folder (str): if specified, will skip downloading from pypi and use it instead
    """

    # paths
    temp_folder = os.path.join(target_folder, f'temp_{pkg_name}')
    extract_folder = os.path.join(temp_folder, 'extracted')
    z_fn = f'{pkg_name}.zip'
    z_fp = os.path.join(temp_folder, z_fn)

    old_pkg_path = os.path.join(target_folder, pkg_name)
    new_pkg_path = os.path.join(extract_folder, pkg_name)

    # make temp folder structure
    delete_folder(temp_folder)
    create_folder(extract_folder)

    # start processing -------------------------------------------------------
    print(f'start updating {pkg_name} please wait ...')

    if create_bkup:
        print(f'backup {pkg_name}')
        bkup(old_pkg_path)

    if not src_folder:
        # get download url
        latest_version, url = get_pkg_latest_version(pkg_name)
        if url:
            print(f'Found {pkg_name} version: {latest_version}')
        else:
            print('Failed to get url for:', pkg_name)
            return

        # download from pypi
        print(f'step 1 of 4: downloading {pkg_name} files')
        data = download(url, fp=z_fp)
        if not data:
            print(f'failed to download {pkg_name}, abort update')
            return

        # extract zip file
        print(f'step 2 of 4: extracting {z_fn}')
        extract(z_fp, extract_folder)

    else:
        # copy pkg folder to temp folder
        shutil.copytree(src_folder, new_pkg_path)

    # compile files from py to pyc
    print('step 3 of 4: compiling files, please wait')
    if compile:
        compile_pkg(new_pkg_path)

    # delete old package and replace it with new one
    print(f'step 4 of 4: overwrite old {pkg_name} files')
    delete_folder(old_pkg_path)
    shutil.move(new_pkg_path, target_folder)
    print('new package copied to:', old_pkg_path)

    # .dist-info folder, eg: FireDM-2021.2.9.dist-info
    r = re.compile(f'{pkg_name}.*dist-info', re.IGNORECASE)

    # delete old dist-info folder if found
    match = list(filter(r.match, os.listdir(target_folder)))
    if match:
        old_dist_info_folder = os.path.join(target_folder, match[0])
        delete_folder(old_dist_info_folder)
        print('delete old dist-info folder:', old_dist_info_folder)

    # copy new dist-info folder to destination folder
    match = list(filter(r.match, os.listdir(extract_folder)))
    if match:
        new_dist_info_folder = os.path.join(extract_folder, match[0])
        shutil.move(new_dist_info_folder, target_folder)
        print('install new dist-info folder:', new_dist_info_folder)

    # clean old files
    print('delete temp folder')
    delete_folder(temp_folder)
    print(f'{pkg_name} ..... done updating')
    return True
Пример #6
0
    def main():
        """
        Main function. Creates Maestro script.
        """

        GLOBAL_VARIABLES = CONFIGURE(args.update)  # configuration_scripts.py

        ligand_main_directory = os.path.abspath("./workspace/ligands")
        ligand_mae_path = os.path.abspath("./workspace/ligand_mae")
        combined_ligand_filename = os.path.abspath("./workspace/ligands/ligs.mae")
        preprocessed_ligand_path = os.path.abspath("./workspace/ligands/preprocessed_ligands")
        # ligand_protein_filename = os.path.abspath("./workspace/all.mae")

        protein_original_path = os.path.abspath("./workspace/proteins")
        # protein_filename = os.path.abspath("bialko.mae")

        # complex_input_filename = os.path.abspath("./workspace/complex/all-out_complex.mae")
        complex_original_path = os.path.abspath("./workspace/complex/original")
        complex_deleted_path = os.path.abspath("./workspace/complex/deleted")

        SMARTS_filename = os.path.abspath("./workspace/SMARTS.txt")

        create_folder(os.path.abspath("./workspace"), True)
        create_folder(os.path.abspath(ligand_main_directory), False)
        create_folder(os.path.abspath(ligand_mae_path), False)
        create_folder(os.path.abspath(preprocessed_ligand_path), False)
        create_folder(os.path.abspath(protein_original_path), False)
        create_folder(os.path.abspath(complex_deleted_path), False)
        create_folder(os.path.abspath(complex_original_path), False)

        """
        workspace
            | SMARTS.txt
            ligands
                | ligs.mae
                ligand_mae
                    | *.mae (from pdb)
                preprocessed_lignads
                    | preprocessed_ligands.pdb
            proteins
                | protein_input.mae
                | protein_deleted.mae
            complex
                original  # not-modified
                    | *.pv (maestro)
                    | *.out_complex
                deleted
                    | *.pv (maestro)
                    | *.out_complex
        """


        ligand_files = []
        try:
            ligand_files = os.listdir(args.ligand)
        except FileNotFoundError:
            print("Folder not found %s" % args.ligand)
            parser.print_help()
            exit()

        # for file in ligand_files:
        #     base = os.path.basename(file)
        #     nazwa = "%s/%s.mae" % (ligand_path, os.path.splitext(base)[0])
        #     os.system("%s %s/run structconvert.py -ipdb %s %s" % (GLOBAL_VARIABLES[1], GLOBAL_VARIABLES[0], file, nazwa))
        # # TODO wyciągnąć nazwy z : jak w file_separate.py
        # titles_file = []

        # for i in os.listdir(ligand_path):
        #     temp = open("%s/%s" % (ligand_path, i)).read()
        #     title0 = temp.split(" :::")[2].split('\n')[1].strip()  # Suitable descriptor for file name can be found here.
        #     title1 = title0.split(":")[-1]
        #     titles_file.append(title1)

        titles_file = []
        for file in ligand_files:
            temp, base_lig = pdb_to_mae(file, ligand_mae_path, GLOBAL_VARIABLES[0], GLOBAL_VARIABLES[1])
            titles_file.append(base_lig)

# TODO #####
        os.system("SCHRODINGER/utilities/structcat %s -omae ./workspace/ligand_mae/ligs.mae" % " ".join("/".join([" ./workspace/ligand_mae/", os.listdir("./workspace/ligand_mae")])))
# TODO #####

        os.system("%s %s/run gen_smarts.py %s/%s %s" % (GLOBAL_VARIABLES[1], GLOBAL_VARIABLES[0], ligand_mae_path, combined_ligand_filename, SMARTS_filename))

        SMARTS = open(SMARTS_filename).readlines()
        SMARTS = [i.rstrip() for i in SMARTS]

        # os.system("%s %s/run structconvert.py -ipdb %s %s" % (GLOBAL_VARIABLES[1], GLOBAL_VARIABLES[0], args.protein, protein_filename))
        ###
        protein_path, protein_base = pdb_to_mae(args.protein, protein_original_path, GLOBAL_VARIABLES[0], GLOBAL_VARIABLES[1])
        ###

        ### łączenie białka z ligandami i usuwanie albo i nie

        # pose_viewer file and complex file for name_prot
        os.system("%s %s/utilities/structcat -imae %s -imae %s -omae %s_pv.mae" % (GLOBAL_VARIABLES[1], GLOBAL_VARIABLES[0], protein_path, combined_ligand_filename, os.path.abspath(complex_original_path + "/" + protein_base)))
        os.system("%s %s/run pv_convert.py -mode merge %s_pv.mae" % (GLOBAL_VARIABLES[1], GLOBAL_VARIABLES[0], os.path.abspath(complex_original_path + "/" + protein_base)))  # TODO ścieżki
        input_file = os.path.abspath(complex_original_path + "/" + protein_base) + "-out_complex.mae"

        # pose_viewer file and complex file for name_prot2
        if args.toaa != 0:
            protein_base_deleted = protein_base + "_deleted"
            protein_path_deleted = os.path.abspath("workspace/" + protein_base_deleted + ".mae")

            os.system("%s %s/run delete_atoms.py -asl \"res.num %s-%s\" %s %s" % (GLOBAL_VARIABLES[1], GLOBAL_VARIABLES[0], args.fromaa, args.toaa, protein_path, protein_path_deleted))
            os.system("%s %s/utilities/structcat -imae %s -imae %s -omae %s_pv.mae" % (GLOBAL_VARIABLES[1], GLOBAL_VARIABLES[0], protein_path_deleted, combined_ligand_filename, os.path.abspath(complex_deleted_path + "/" + protein_base_deleted)))
            os.system("%s %s/run pv_convert.py -mode merge %s_pv.mae" % (GLOBAL_VARIABLES[1], GLOBAL_VARIABLES[0], os.path.abspath(complex_deleted_path + "/" + protein_base_deleted)))
            input_file = os.path.abspath(complex_deleted_path + "/" + protein_base_deleted + "-out_complex.mae")

        maestro_writer(args.output, args.crystal, input_file, titles_file, SMARTS)  # utils.py

        if args.remove:
            paths = [os.path.abspath("./workspace")]  # Folders to clean.
            cleanup(paths)  # utils.py
Пример #7
0
project_folder = os.path.dirname(os.path.dirname(current_folder))
build_folder = current_folder
app_folder = os.path.join(build_folder, APP_NAME)
icon_path = os.path.join(
    project_folder, 'icons',
    '48_32_16.ico')  # best use size 48, and must be an "ico" format
version_fp = os.path.join(project_folder, 'firedm', 'version.py')
requirements_fp = os.path.join(project_folder, 'requirements.txt')
main_script_path = os.path.join(project_folder, 'firedm.py')

sys.path.insert(0, project_folder)  # for imports to work
from scripts.utils import download, delete_folder, create_folder

# create build folder
create_folder(build_folder)

# get version
version_module = {}
with open(version_fp) as f:
    exec(
        f.read(),
        version_module)  # then we can use it as: version_module['__version__']
    version = version_module['__version__']

# get required packages
with open(requirements_fp) as f:
    packages = [
        line.strip().split(' ')[0] for line in f.readlines() if line.strip()
    ] + ['firedm']
    packages.remove('Pillow')
Пример #8
0
def update_pkg(pkg_name,
               target_folder,
               src_folder=None,
               create_bkup=False,
               compile=True):
    """install or update a packagein a specific folder
    expect to download and extract a wheel file e.g. "yt_dlp-2020.10.24.post6-py2.py3-none-any.whl", which in fact
    is a zip file

    Args:
        pkg_name (str): package name
        url (str): download url (for a wheel file)
        target_folder (str): target installation folder for the package
        src_folder (str): if specified, will skip downloading from pypi and use it instead
    """

    # paths
    temp_folder = os.path.join(target_folder, f'temp_{pkg_name}')
    extract_folder = os.path.join(temp_folder, 'extracted')
    z_fn = f'{pkg_name}.zip'
    z_fp = os.path.join(temp_folder, z_fn)

    old_pkg_path = os.path.join(target_folder, pkg_name)
    new_pkg_path = os.path.join(extract_folder, pkg_name)

    delete_folder(temp_folder)

    # start processing -------------------------------------------------------
    print(f'start updating {pkg_name} please wait ...')

    if create_bkup:
        print(f'backup {pkg_name}')
        bkup(old_pkg_path)

    if src_folder:
        # copy pkg folder to temp folder
        shutil.copytree(src_folder, new_pkg_path, dirs_exist_ok=True)

    else:

        # get download url
        latest_version, url = get_pkg_latest_version(pkg_name)
        current_version = get_pkg_version(old_pkg_path)
        print(
            f'{pkg_name}, current: {current_version} - latest: {latest_version}'
        )
        if parse_version(latest_version) <= parse_version(current_version):
            print(f'{pkg_name} is up-to-date')
            return

        if url:
            print(f'Found {pkg_name} version: {latest_version}')
        else:
            print('Failed to get url for:', pkg_name)
            return

        # download from pypi
        print(f'downloading {pkg_name} files')
        data = download(url, fp=z_fp)
        if not data:
            print(f'failed to download {pkg_name}, abort update')
            return

        # make temp folder structure
        create_folder(extract_folder)

        # extract zip file
        print(f'extracting {z_fn}')
        extract(z_fp, extract_folder)

    # # compile files from py to pyc
    # if compile:
    #     print('compiling files, please wait')
    #     compile_pkg(new_pkg_path)

    # # delete old package and replace it with new one
    # print(f'overwrite old {pkg_name} files')
    # delete_folder(old_pkg_path)
    # shutil.move(new_pkg_path, target_folder)
    # print('new package copied to:', old_pkg_path)

    # .dist-info folder, eg: FireDM-2021.2.9.dist-info
    r = re.compile(f'{pkg_name}.*dist-info', re.IGNORECASE)

    # delete old dist-info folder if found
    match = list(filter(r.match, os.listdir(target_folder)))
    if match:
        old_dist_info_folder = os.path.join(target_folder, match[0])
        delete_folder(old_dist_info_folder)
        print('delete old dist-info folder:', old_dist_info_folder)

    # # copy new dist-info folder to destination folder
    # match = list(filter(r.match, os.listdir(extract_folder)))
    # if match:
    #     new_dist_info_folder = os.path.join(extract_folder, match[0])
    #     shutil.move(new_dist_info_folder, target_folder)
    #     print('install new dist-info folder:', new_dist_info_folder)

    # move folders under extracted folder to target folder (e.g: sitepackages)
    src, dest = extract_folder, target_folder
    folders = [
        f for f in os.listdir(src) if os.path.isdir(os.path.join(src, f))
    ]

    # execlude .data folders
    folders = [f for f in folders if not f.endswith('.data')]

    src_folders = [os.path.join(src, f) for f in folders]
    dest_folders = [os.path.join(dest, f) for f in folders]

    # delete dest folders
    for folder in dest_folders:
        delete_folder(folder)

    for folder in src_folders:
        shutil.move(folder, dest)

    # clean old files
    delete_folder(temp_folder, verbose=True)
    print(f'{pkg_name} ..... done updating \n')
    return True