Skip to content

Commit

Permalink
v0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
BHM-Bob committed Sep 4, 2024
1 parent f7c01e6 commit 73469ec
Show file tree
Hide file tree
Showing 7 changed files with 354 additions and 8 deletions.
18 changes: 17 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,20 @@
Now, lazydock only support pypi install:
```
pip install lazydock
```
```


## Contains

### pymol utils - pml
- [autodock](pml/autodock_utils.md): parse autodock results to pdb pose.
- [interaction](pml/interaction_utils.md): calculate interactions between receptor and poses.
- [server](pml/server.md): provide a server-client interface to communicate with pymol.
- [shader](pml/shader.md): provide a shader for pymol.

### pyroseeta utils - pyrt
- [pose](pyrt/pose.md): provide a wrapper pose class to opt pose.


## release note
- [0.2.0](release_note/0.2.0.md)
102 changes: 102 additions & 0 deletions docs/pml/server.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Overview
This module provides a client-server architecture for interacting with PyMOL, a molecular visualization system. The `VServer` class runs on the server side, listening for connections and executing PyMOL commands sent by the client. The `VClient` class is used on the client side to send commands to the server. The `PymolAPI` class acts as a wrapper for PyMOL's API, providing a convenient interface for command execution.

# Classes
## `PymolAPI`
### Description
A wrapper class for PyMOL's API, allowing for the execution of PyMOL commands (`cmd`) or API functions (`api`) through a client-server architecture.

### Methods
#### `send_action(api: str, fn: str, *args, **kwargs) -> Any`
##### Description
Sends an action to the server to be executed.

##### Parameters
- `api`: The API type ('cmd' or 'api').
- `fn`: The function name to execute.
- `*args`: Positional arguments for the function.
- `**kwargs`: Keyword arguments for the function.

##### Returns
- `Any`: The return value of the executed function.

## `VServer`
### Description
A server class that listens for connections from clients and executes PyMOL commands sent by the clients.

### Methods
#### `copy_logs() -> List[str]`
##### Description
Copies the server logs.

##### Returns
- `List[str]`: A list of log strings.

#### `copy_new_logs() -> List[str]`
##### Description
Copies new logs since the last check.

##### Returns
- `List[str]`: A list of new log strings.

#### `_add_log(log: str, verbose: bool = False) -> None`
##### Description
Adds a log entry.

##### Parameters
- `log`: The log message.
- `verbose`: Whether to print the log message.

#### `_recvall(sock: socket.socket, count: int)`
##### Description
Receives all data from the socket.

##### Parameters
- `sock`: The socket object.
- `count`: The number of bytes to receive.

#### `_sendall(scok: socket.socket, data: bytes) -> None`
##### Description
Sends all data to the socket.

##### Parameters
- `scok`: The socket object.
- `data`: The data to send.

#### `_run_server() -> None`
##### Description
The main loop of the server, running in a separate thread, listening for connections and executing commands.

## `VClient`
### Description
A client class that connects to the server and sends commands to be executed in PyMOL.

### Methods
#### `send_action(api: str, fn: str, *args, **kwargs) -> Any`
##### Description
Sends an action to the server to be executed.

##### Parameters
- `api`: The API type ('cmd' or 'api').
- `fn`: The function name to execute.
- `*args`: Positional arguments for the function.
- `**kwargs`: Keyword arguments for the function.

##### Returns
- `Any`: The return value of the executed function.

#### `sen_quit() -> None`
##### Description
Sends a quit command to the server and closes the connection.

## Functions
### `_test_server()`
##### Description
A test function to start the server and print logs.

### `_test_client()`
##### Description
A test function to start the client, connect to the server, and execute a PyMOL command.

# Main Execution
The provided code includes a main execution block that starts both the server and client in separate processes, allowing for testing of the client-server architecture.
175 changes: 175 additions & 0 deletions docs/pml/shader.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# Overview
This module provides a set of classes and functions designed to coloring molecular in PyMOL. It includes classes to represent atoms and residues with associated data, and a `Shader` class to apply color gradients based on calculated interaction values.

# Functions
## `get_c_value()`
### Description
Retrieves the `c_value` for a `ShaderRes` instance. If `c_value` is not set, it calculates the sum of `c_values` of its atoms.

### Parameters
- None

### Returns
- `float`: The `c_value` of the residue.

### Notes
- The `c_value` is only recalculated if `atoms` is updated after the initial calculation.

# Classes
## `ShaderAtom`
### Description
A data class representing an atom in a molecular model with properties such as model, chain, residue index, element, and an optional `c_value` for coloring.

### Members
- `model`: The model name.
- `chain`: The chain identifier.
- `resi`: The residue index.
- `elem`: The element type.
- `index`: The atom index.
- `c_value`: An optional float value associated with the atom.
- `alpha`: An optional float representing the opacity.

## `ShaderRes`
### Description
A data class representing a residue in a molecular model, containing a list of `ShaderAtom` instances and optional `c_value` and `alpha` properties.

### Methods
#### `get_c_value()`
##### Description
Retrieves the `c_value` for the residue. If not set, it calculates the sum of `c_values` of its atoms.

##### Parameters
- None

##### Returns
- `float`: The `c_value` of the residue.

### Members
- `atoms`: A list of `ShaderAtom` instances.
- `c_value`: An optional float value associated with the residue.
- `alpha`: An optional float representing the opacity.

## `ShaderValues`
### Description
A class to manage and retrieve `c_values` for chains, residues, and atoms in a molecular model.

### Methods
#### `get_c_value(chain: str, resi: int, atom_index: int = None) -> float`
##### Description
Retrieves the `c_value` for a specified chain, residue, and optionally an atom.

##### Parameters
- `chain`: The chain identifier.
- `resi`: The residue index.
- `atom_index`: The optional atom index.

##### Returns
- `float`: The `c_value` for the specified atom or residue.

#### `get_all_c_values(level: str = 'res') -> list`
##### Description
Retrieves all `c_values` for the specified level (residue or atom).

##### Parameters
- `level`: The level of detail ('res' for residue, 'atom' for atom).

##### Returns
- `list`: A list of tuples containing model, chain, residue index, atom index (if applicable), alpha, and `c_value`.

#### `from_interaction_df(df: Union[str, pd.DataFrame], model: str, sum_axis: int = 0) -> ShaderValues`
##### Description
Loads `c_values` from an interaction data frame.

##### Parameters
- `df`: The data frame or path to the data frame.
- `model`: The model name.
- `sum_axis`: The axis along which to sum the data frame.

##### Returns
- `ShaderValues`: The instance itself after loading the data.

## `Shader`
### Description
A class to apply color gradients to molecular models in PyMOL based on `c_values`.

### Methods
#### `get_col_from_c_value(c_value: float) -> (tuple, str)`
##### Description
Returns the RGBA color and a color name for a given `c_value`.

##### Parameters
- `c_value`: The `c_value` for which to generate the color.

##### Returns
- `tuple`: The RGBA color.
- `str`: The color name.

#### `_get_rgba_col_name(c_value: float, _col_name: str = None, _cmd = None) -> (tuple, str)`
##### Description
Generates the RGBA color and a color name for a given `c_value`, storing it globally if it doesn't exist.

##### Parameters
- `c_value`: The `c_value` for which to generate the color.
- `_col_name`: An optional predefined color name.
- `_cmd`: The PyMOL command module.

##### Returns
- `tuple`: The RGBA color.
- `str`: The color name.

#### `create_colors_in_pml(values: ShaderValues, level: str = 'res', names: List[str] = None, _cmd = None)`
##### Description
Creates colors in PyMOL for each `c_value` in the provided `ShaderValues`.

##### Parameters
- `values`: The `ShaderValues` instance.
- `level`: The level of detail ('res' for residue, 'atom' for atom).
- `names`: An optional list of predefined color names.
- `_cmd`: The PyMOL command module.

#### `auto_scale_norm(c_values)`
##### Description
Automatically scales the normalization based on the provided `c_values`.

##### Parameters
- `c_values`: A list of `c_values` to use for scaling.

#### `apply_shader_values(values: ShaderValues, level: str = 'res', auto_detect_vlim: bool = True, alpha_mode: str = None, _cmd = None)`
##### Description
Applies the shader values to a molecular model in PyMOL.

##### Parameters
- `values`: The `ShaderValues` instance.
- `level`: The level of detail ('res' for residue, 'atom' for atom).
- `auto_detect_vlim`: Whether to automatically detect the color limits.
- `alpha_mode`: An optional transparency mode for PyMOL.
- `_cmd`: The PyMOL command module.

#### `apply_shader_values_to_selection(selection, c_value: float = None, alpha: float = 1.0, alpha_mode: str = None, _cmd = None)`
##### Description
Applies the shader values to a specific selection in PyMOL.

##### Parameters
- `selection`: The selection to which the shader values will be applied.
- `c_value`: An optional `c_value` for the color.
- `alpha`: The opacity level.
- `alpha_mode`: An optional transparency mode for PyMOL.
- `_cmd`: The PyMOL command module.

#### `apply_shader_values_to_sele(select_expression: str, c_value: float = None, alpha: float = 1.0, alpha_mode: str = None, _cmd = None)`
##### Description
Applies the shader values to a selection expression in PyMOL.

##### Parameters
- `select_expression`: The selection expression to which the shader values will be applied.
- `c_value`: An optional `c_value` for the color.
- `alpha`: The opacity level.
- `alpha_mode`: An optional transparency mode for PyMOL.
- `_cmd`: The PyMOL command module.

#### `__repr__(self)`
##### Description
Returns a string representation of the `Shader` instance.

##### Returns
- `str`: The string representation.
53 changes: 53 additions & 0 deletions docs/release_notes/0.2.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!--
* @Date: 2024-09-04 21:34:10
* @LastEditors: BHM-Bob [email protected]
* @LastEditTime: 2024-09-04 21:41:45
* @Description:
-->
2024/9/4 21:31:18


## Focus on
1. Add pml.shader and pml.server sub-module


## What's New
- addon: add lazydock\pml\shader.py
- addon: lazydock\pml\server.py
- addon: add lazydock_pymol_plugin\lazy_plot.py
- addon: lazydock_pymol_plugin\__init__.py: extend new cmd: start_lazydock_server
- addon: lazydock\pml\shader.py: ShaderValues: add method from_interaction_df
- addon: lazydock\pml\shader.py: Shader: add __repr__ method
- addon: lazydock\pml\shader.py: Shader: add method auto_scale_norm, apply_shader_values_to_selection, apply_shader_values_to_sele


## Minor Addon
- minor-addon: lazydock\pml\shader.py: Shader: apply_shader_values: add alpha_mode argument
- minor-addon: lazydock\pml\shader.py: Shader: support global_name2col and norm
- minor-addon: lazydock\pml\server.py: add data-length to enssure server can read all data
- minor-addon: lazydock\pml\shader.py: add _cmd option
- minor-addon: lazydock\pml\server.py: VClient: send_action: support return the return value of an action
- minor-addon: lazydock_pymol_plugin\__init__.py: start_lazydock_server: add start log


## BUG-FIX
- fix-bug: lazydock\pml\shader.py: from_interaction_df: skip first row now
- fix-bug: lazydock\pml\shader.py: fix _cmd argument passing


## CODE-FIX
- fix-code: lazydock\pml\interaction_utils.py: add __all__
- fix-code: lazydock_pymol_plugin\main.py: GUILauncher: add lazy_plot_tab
- fix-code: lazydock_pymol_plugin\lazy_plot.py: move pymol import to dev code


## Remove
None or a little.


## Other Changes
None or a little.


## Details
**完整的更新日志**: https://gitee.com/bhm-bob/LazyDock/commits/v0.2.0
6 changes: 3 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'''
Date: 2024-08-24 22:24:47
LastEditors: BHM-Bob [email protected]
LastEditTime: 2024-08-27 10:30:53
LastEditTime: 2024-09-04 21:43:47
Description:
'''
# Configuration file for the Sphinx documentation builder.
Expand All @@ -12,8 +12,8 @@
copyright = '2024, BHM-Bob'
author = 'BHM-Bob G'

release = '0.1.0'
version = '0.1.0'
release = '0.2.0'
version = '0.2.0'

# -- General configuration

Expand Down
4 changes: 2 additions & 2 deletions lazydock/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
__title__ = "lazydock"
__description__ = "Lazy Dock"
__url__ = "https://github.com/BHM-Bob/LazyDock"
__version__ = "0.1.0"
__build__ = "20240827_0"
__version__ = "0.2.0"
__build__ = "20240904_0"
__author__ = "BHM-Bob G"
__author_email__ = "[email protected]"
__license__ = "MIT"
Loading

0 comments on commit 73469ec

Please sign in to comment.