Module deeporigin.src.progress_view

Classes

class DockingViewer (protein_content=None,
protein_format=None,
protein_path=None,
pocket_center=None,
dim=None)
Expand source code
class DockingViewer:
    def __init__(self, protein_content=None, protein_format=None, protein_path=None, pocket_center=None, dim=None):
        self.viewer_id = random.randint(10**8, 10**9 - 1)
        self.viewer_var = f"viewer_{self.viewer_id}"

        if protein_path is not None:
            protein_content = open(protein_path, "r").read()
            protein_format = protein_path.split(".")[-1]
        elif protein_content is None or protein_format is None:
            raise Exception("You should spceify protein content and format or protein path.")

        protein_content = protein_content.replace("\n", "\\n")

        x, y, z = 0, 0, 0
        if pocket_center is not None and dim is not None:
            self.content = BASE_CONTENT.replace("#pocket_view_setting", "setPocketView(viewer_#viewer_id, #pocket_config_placeholder);")
            x, y, z = pocket_center
        else:
            self.content = BASE_CONTENT.replace("#pocket_view_setting", "")

        self.content = self.content.replace("#viewer_id", str(self.viewer_id)).replace("#protein_content", protein_content).replace("#protein_format", protein_format).replace("#pocket_config_placeholder", f"{{ center: {{x: {x}, y: {y}, z: {z}}}, dim: {dim}}}")

    def _repr_html_(self):
        return self.content

    def update_ligand(self, ligand_content):
        ligand_content = ligand_content.replace("\n", "\\n")
        return display(HTML(f"<script>updateLigand({self.viewer_var}, {{content: \"{ligand_content}\", format: \"sdf\"}})</script>"))        

Methods

def update_ligand(self, ligand_content)
Expand source code
def update_ligand(self, ligand_content):
    ligand_content = ligand_content.replace("\n", "\\n")
    return display(HTML(f"<script>updateLigand({self.viewer_var}, {{content: \"{ligand_content}\", format: \"sdf\"}})</script>"))        
class ProgressView (desc='', progress_only=True, docking_viewer=None)
Expand source code
class ProgressView:
    def __init__(self, desc="", progress_only=True, docking_viewer=None):
        self.progress_only = progress_only

        self.description = desc
        self.bar_output = Output()
        with self.bar_output:
            self.bar = tqdm(total=100, file=sys.stdout, ncols=50, bar_format=f'{desc}: {{percentage:3.0f}}% | Elapsed Time: {{elapsed}}')

        self.docking_viewer_output = None
        if not self.progress_only and docking_viewer is not None:
            self.docking_viewer_output = Output()
            with self.docking_viewer_output:
                self.docking_viewer = docking_viewer
                display(self.docking_viewer)

        self.displayed = False

    def display(self):
        if not self.displayed:
            self.displayed = True
            display(self.bar_output)
            if self.docking_viewer_output is not None:
                display(self.docking_viewer_output)

    def update(self, new_desc=None, new_percentage=None, new_ligand_content=None):
        if new_desc is not None:
            with self.bar_output:
                self.bar.bar_format = f'{new_desc}: {{percentage:3.0f}}% | Elapsed Time: {{elapsed}}'

        if new_percentage is not None:
            with self.bar_output:
                if self.bar.n <= new_percentage:
                    self.bar.update(new_percentage - self.bar.n)

        if new_ligand_content is not None and self.docking_viewer_output is not None:
            with self.docking_viewer_output:
                self.docking_viewer.update_ligand(new_ligand_content)

        with self.bar_output:
            self.bar.display()

    def close(self):
        with self.bar_output:
            self.bar.close()
            self.bar = None

Methods

def close(self)
Expand source code
def close(self):
    with self.bar_output:
        self.bar.close()
        self.bar = None
def display(self)
Expand source code
def display(self):
    if not self.displayed:
        self.displayed = True
        display(self.bar_output)
        if self.docking_viewer_output is not None:
            display(self.docking_viewer_output)
def update(self, new_desc=None, new_percentage=None, new_ligand_content=None)
Expand source code
def update(self, new_desc=None, new_percentage=None, new_ligand_content=None):
    if new_desc is not None:
        with self.bar_output:
            self.bar.bar_format = f'{new_desc}: {{percentage:3.0f}}% | Elapsed Time: {{elapsed}}'

    if new_percentage is not None:
        with self.bar_output:
            if self.bar.n <= new_percentage:
                self.bar.update(new_percentage - self.bar.n)

    if new_ligand_content is not None and self.docking_viewer_output is not None:
        with self.docking_viewer_output:
            self.docking_viewer.update_ligand(new_ligand_content)

    with self.bar_output:
        self.bar.display()