def __init__(self, setup_dic): self.setup_dic = setup_dic if not self.check_setup_dic(setup_dic): raise SetupError('+ Error: Please configure your setup file') self.protocol_path = get_full_path('haddock', 'protocols') with open(f'{etc_folder}/default.json', 'r') as fh: self.default_recipes = json.load(fh) fh.close() run_id = None try: run_id = self.setup_dic['identifier']['run'] except KeyError: raise SetupError('+ ERROR: Run identifier not provided') for mol in self.setup_dic['molecules']: target_mol = self.setup_dic['molecules'][mol] if not os.path.isfile(target_mol): raise SetupError(f'+ ERROR: Molecule {target_mol} not found') self.run_dir = None if type(run_id) == int: self.run_dir = f"run{run_id}" elif type(run_id) == str: run_id = run_id.replace(' ', '-') self.run_dir = f"run-{run_id}" else: raise SetupError( '+ ERROR: Run identifier can only be string or integer')
def load_ini(ini_file): etc_folder = get_full_path('haddock', 'etc') config_file = os.path.join(etc_folder, ini_file) ini = configparser.ConfigParser(os.environ) ini.read(config_file, encoding='utf-8') return ini
def __init__(self, recipe_file, default_params, custom_params): self.protocol_path = get_full_path('haddock', 'protocols') self.recipe_name = recipe_file.split('.')[0] self.recipe = f'{self.protocol_path}/{self.recipe_name}/{recipe_file}' # recipe_params = self.protocol_path + '/' + recipe_file.split('.')[0] + '.json' # if os.path.isfile(recipe_params): # with open(recipe_params, 'r') as f: # self.recipe_params = json.load(f) # f.close() # else: # print(f'+ ERROR: Default parameters not found for {recipe_file}') # exit() self.default_params = default_params self.custom_params = custom_params
import shutil import statistics import math import subprocess import itertools import configparser import operator from haddock.modules.structure.utils import PDB from haddock.utils.files import get_full_path from haddock.modules.analysis.fcc import read_matrix, cluster_elements, output_clusters from haddock.modules.analysis.contact import Contacts from haddock.modules.analysis.dfire import dfire from haddock.modules.analysis.dockq import dockq from haddock.modules.analysis.fastcontact import fastcontact etc_folder = get_full_path('haddock', 'etc') config_file = os.path.join(etc_folder, 'haddock3.ini') ini = configparser.ConfigParser(os.environ) ini.read(config_file, encoding='utf-8') class Ana: def __init__(self, pdb_l): self.structure_dic = {} self.contact_filelist = [] self.structure_haddockscore_list = [] self.fcc_matrix_f = 'fcc.matrix' self.ss_output_f = 'ss' self.cluster_output_f = 'cluster'
""" Test the PDB utilities """ import filecmp import unittest import os from shutil import copyfile from haddock.modules.structure.utils import PDB from haddock.utils.files import get_full_path data_path = get_full_path('test', 'data') class TestPDB(unittest.TestCase): def setUp(self): self.PDB = PDB() def test_treat_ensemble(self): copyfile(f'{data_path}/mini_ens.pdb', f'{data_path}/temp_ens.pdb') input_pdb_dic = {'mol1': f'{data_path}/temp_ens.pdb'} treated_dic = self.PDB.treat_ensemble(input_pdb_dic) expected_treated_dic = {'mol1': [f'{data_path}/temp_1.pdb', f'{data_path}/temp_2.pdb']} self.assertEqual(treated_dic, expected_treated_dic) self.assertTrue(filecmp.cmp(f'{data_path}/temp_1.pdb', f'{data_path}/mini_ens1.pdb')) self.assertTrue(filecmp.cmp(f'{data_path}/temp_2.pdb', f'{data_path}/mini_ens2.pdb')) os.remove(f'{data_path}/temp_1.pdb') os.remove(f'{data_path}/temp_2.pdb') os.remove(f'{data_path}/temp_ens.pdb')
import os import string import configparser from itertools import chain from haddock.utils.files import get_full_path # from haddock.modules.structure.reduce import analyze_protonation_state etc_folder = get_full_path('haddock', 'etc') config_file = os.path.join(etc_folder, 'haddock3.ini') ini = configparser.ConfigParser(os.environ) ini.read(config_file, encoding='utf-8') src_path = get_full_path('haddock', 'src') def histogram(items): for c, n in items: if n / 10 > 1: output = int(n / 10) * '-' print(f' {c}\t{output} ({n})') def pad_line(line): # borrowed from from pdb-tools (: """Helper function to pad line to 80 characters in case it is shorter""" size_of_line = len(line) if size_of_line < 80: padding = 80 - size_of_line + 1 line = line.strip('\n') + ' ' * padding + '\n'