proteusPy.hexbin_plot
hexbin_plotter.py Purpose: Create hexbin plots with customizable parameters. Usage: python hexbin_plotter.py [arguments] Author: Eric G. Suchanek, PhD.
1""" 2hexbin_plotter.py 3Purpose: Create hexbin plots with customizable parameters. 4Usage: python hexbin_plotter.py [arguments] 5Author: Eric G. Suchanek, PhD. 6""" 7 8# pylint: disable=c0103 9 10import argparse 11import logging 12import sys 13 14import proteusPy as pp 15 16 17def setup_logging(log_file: str, log_level: str = "INFO") -> logging.Logger: 18 """ 19 Set up logging configuration. 20 21 :param log_file: Output log file name 22 :param log_level: Logging level (default: "INFO") 23 :return: Configured logger instance 24 """ 25 pp.configure_master_logger(log_file) 26 pp.set_logger_level_for_module("proteusPy", getattr(logging, log_level.upper())) 27 return pp.create_logger(__name__) 28 29 30def create_hexbin_plot( 31 plot_type: str = "df", 32 column1: str = "chi2", 33 column2: str = "chi4", 34 width: int = 1024, 35 height: int = 1024, 36 gridsize: int = 100, 37 scaling: str = "sqrt", 38 percentile: float = None, 39 verbose: bool = False, 40 title: str = None, 41) -> None: 42 """ 43 Create a hexbin plot with specified parameters. 44 45 :param plot_type: Type of hexbin plot ('leftright' or 'df') 46 :type plot_type: str 47 :param column1: First column name for plotting 48 :type column1: str 49 :param column2: Second column name for plotting 50 :type column2: str 51 :param width: Plot width in pixels (default: 1024) 52 :type width: int 53 :param height: Plot height in pixels (default: 1024) 54 :type height: int 55 :param gridsize: Number of hexagons in grid (default: 100) 56 :type gridsize: int 57 :param scaling: Scaling method ('sqrt', 'linear', etc.) (default: 'sqrt') 58 :type scaling: str 59 :param percentile: Cutoff value for data loading (default: None) 60 :type percentile: float 61 :param verbose: Enable verbose output (default: False) 62 :type verbose: bool 63 """ 64 # Load PDB data 65 if percentile > 0: 66 PDB = pp.DisulfideLoader(verbose=verbose, percentile=percentile) 67 else: 68 PDB = pp.Load_PDB_SS(verbose=verbose, subset=False) 69 70 # Create plot based on type 71 if plot_type.lower() == "leftright": 72 PDB.plot_3d_hexbin_leftright( 73 scaling=scaling, 74 width=width, 75 height=height, 76 gridsize=gridsize, 77 column1=column1, 78 column2=column2, 79 title=title, 80 ) 81 elif plot_type.lower() == "df": 82 pp.DisulfideVisualization.plot_3d_hexbin_df( 83 df=PDB.TorsionDF, 84 column1=column1, 85 column2=column2, 86 width=width, 87 height=height, 88 gridsize=gridsize, 89 scaling=scaling, 90 title=title, 91 ) 92 else: 93 raise ValueError(f"Unsupported plot type: {plot_type}. Use 'leftright' or 'df'") 94 95 96def main(): 97 """Main function to parse arguments and create hexbin plot.""" 98 parser = argparse.ArgumentParser(description="Create hexbin plots with proteusPy") 99 parser.add_argument( 100 "plot_type", choices=["leftright", "df"], help="Type of hexbin plot to create" 101 ) 102 parser.add_argument( 103 "column1", 104 choices=["chi1", "chi2", "chi3", "chi4", "chi5", "energy", "rho"], 105 help="First column name for plotting", 106 ) 107 parser.add_argument( 108 "column2", 109 choices=["chi1", "chi2", "chi3", "chi4", "chi5", "energy", "rho"], 110 help="Second column name for plotting", 111 ) 112 parser.add_argument( 113 "--width", type=int, default=1024, help="Plot width in pixels (default: 1024)" 114 ) 115 parser.add_argument( 116 "--height", type=int, default=1024, help="Plot height in pixels (default: 1024)" 117 ) 118 parser.add_argument( 119 "--gridsize", 120 type=int, 121 default=80, 122 help="Number of hexagons in grid (default: 100)", 123 ) 124 parser.add_argument( 125 "--scaling", 126 default="sqrt", 127 help="Scaling method (default: sqrt)", 128 choices=["sqrt", "linear", "log", "power"], 129 ) 130 parser.add_argument( 131 "--percentile", 132 type=float, 133 default=-1.0, 134 help="Percentile cutoff to build the dataset (default: -1.0)", 135 ) 136 parser.add_argument( 137 "--log-file", 138 default="hexbin_plot.log", 139 help="Output log file name (default: hexbin_plot.log)", 140 ) 141 parser.add_argument( 142 "--log-level", 143 default="INFO", 144 choices=["DEBUG", "INFO", "WARNING", "ERROR"], 145 help="Logging level (default: INFO)", 146 ) 147 parser.add_argument( 148 "--verbose", action="store_true", help="Enable verbose output (default: False)" 149 ) 150 151 args = parser.parse_args() 152 153 # Setup environment and logging 154 pp.set_pyvista_theme("auto") 155 logger = setup_logging(args.log_file, args.log_level) 156 157 try: 158 create_hexbin_plot( 159 plot_type=args.plot_type, 160 column1=args.column1, 161 column2=args.column2, 162 width=args.width, 163 height=args.height, 164 gridsize=args.gridsize, 165 scaling=args.scaling, 166 percentile=args.percentile, 167 verbose=args.verbose, 168 ) 169 logger.info("Plot created successfully") 170 except ValueError as e: 171 logger.error("Error creating plot: %s", e) 172 sys.exit(1) 173 174 175if __name__ == "__main__": 176 main() 177 sys.exit(0)
def
setup_logging(log_file: str, log_level: str = 'INFO') -> logging.Logger:
18def setup_logging(log_file: str, log_level: str = "INFO") -> logging.Logger: 19 """ 20 Set up logging configuration. 21 22 :param log_file: Output log file name 23 :param log_level: Logging level (default: "INFO") 24 :return: Configured logger instance 25 """ 26 pp.configure_master_logger(log_file) 27 pp.set_logger_level_for_module("proteusPy", getattr(logging, log_level.upper())) 28 return pp.create_logger(__name__)
Set up logging configuration.
Parameters
- log_file: Output log file name
- log_level: Logging level (default: "INFO")
Returns
Configured logger instance
def
create_hexbin_plot( plot_type: str = 'df', column1: str = 'chi2', column2: str = 'chi4', width: int = 1024, height: int = 1024, gridsize: int = 100, scaling: str = 'sqrt', percentile: float = None, verbose: bool = False, title: str = None) -> None:
31def create_hexbin_plot( 32 plot_type: str = "df", 33 column1: str = "chi2", 34 column2: str = "chi4", 35 width: int = 1024, 36 height: int = 1024, 37 gridsize: int = 100, 38 scaling: str = "sqrt", 39 percentile: float = None, 40 verbose: bool = False, 41 title: str = None, 42) -> None: 43 """ 44 Create a hexbin plot with specified parameters. 45 46 :param plot_type: Type of hexbin plot ('leftright' or 'df') 47 :type plot_type: str 48 :param column1: First column name for plotting 49 :type column1: str 50 :param column2: Second column name for plotting 51 :type column2: str 52 :param width: Plot width in pixels (default: 1024) 53 :type width: int 54 :param height: Plot height in pixels (default: 1024) 55 :type height: int 56 :param gridsize: Number of hexagons in grid (default: 100) 57 :type gridsize: int 58 :param scaling: Scaling method ('sqrt', 'linear', etc.) (default: 'sqrt') 59 :type scaling: str 60 :param percentile: Cutoff value for data loading (default: None) 61 :type percentile: float 62 :param verbose: Enable verbose output (default: False) 63 :type verbose: bool 64 """ 65 # Load PDB data 66 if percentile > 0: 67 PDB = pp.DisulfideLoader(verbose=verbose, percentile=percentile) 68 else: 69 PDB = pp.Load_PDB_SS(verbose=verbose, subset=False) 70 71 # Create plot based on type 72 if plot_type.lower() == "leftright": 73 PDB.plot_3d_hexbin_leftright( 74 scaling=scaling, 75 width=width, 76 height=height, 77 gridsize=gridsize, 78 column1=column1, 79 column2=column2, 80 title=title, 81 ) 82 elif plot_type.lower() == "df": 83 pp.DisulfideVisualization.plot_3d_hexbin_df( 84 df=PDB.TorsionDF, 85 column1=column1, 86 column2=column2, 87 width=width, 88 height=height, 89 gridsize=gridsize, 90 scaling=scaling, 91 title=title, 92 ) 93 else: 94 raise ValueError(f"Unsupported plot type: {plot_type}. Use 'leftright' or 'df'")
Create a hexbin plot with specified parameters.
Parameters
- plot_type: Type of hexbin plot ('leftright' or 'df')
- column1: First column name for plotting
- column2: Second column name for plotting
- width: Plot width in pixels (default: 1024)
- height: Plot height in pixels (default: 1024)
- gridsize: Number of hexagons in grid (default: 100)
- scaling: Scaling method ('sqrt', 'linear', etc.) (default: 'sqrt')
- percentile: Cutoff value for data loading (default: None)
- verbose: Enable verbose output (default: False)
def
main():
97def main(): 98 """Main function to parse arguments and create hexbin plot.""" 99 parser = argparse.ArgumentParser(description="Create hexbin plots with proteusPy") 100 parser.add_argument( 101 "plot_type", choices=["leftright", "df"], help="Type of hexbin plot to create" 102 ) 103 parser.add_argument( 104 "column1", 105 choices=["chi1", "chi2", "chi3", "chi4", "chi5", "energy", "rho"], 106 help="First column name for plotting", 107 ) 108 parser.add_argument( 109 "column2", 110 choices=["chi1", "chi2", "chi3", "chi4", "chi5", "energy", "rho"], 111 help="Second column name for plotting", 112 ) 113 parser.add_argument( 114 "--width", type=int, default=1024, help="Plot width in pixels (default: 1024)" 115 ) 116 parser.add_argument( 117 "--height", type=int, default=1024, help="Plot height in pixels (default: 1024)" 118 ) 119 parser.add_argument( 120 "--gridsize", 121 type=int, 122 default=80, 123 help="Number of hexagons in grid (default: 100)", 124 ) 125 parser.add_argument( 126 "--scaling", 127 default="sqrt", 128 help="Scaling method (default: sqrt)", 129 choices=["sqrt", "linear", "log", "power"], 130 ) 131 parser.add_argument( 132 "--percentile", 133 type=float, 134 default=-1.0, 135 help="Percentile cutoff to build the dataset (default: -1.0)", 136 ) 137 parser.add_argument( 138 "--log-file", 139 default="hexbin_plot.log", 140 help="Output log file name (default: hexbin_plot.log)", 141 ) 142 parser.add_argument( 143 "--log-level", 144 default="INFO", 145 choices=["DEBUG", "INFO", "WARNING", "ERROR"], 146 help="Logging level (default: INFO)", 147 ) 148 parser.add_argument( 149 "--verbose", action="store_true", help="Enable verbose output (default: False)" 150 ) 151 152 args = parser.parse_args() 153 154 # Setup environment and logging 155 pp.set_pyvista_theme("auto") 156 logger = setup_logging(args.log_file, args.log_level) 157 158 try: 159 create_hexbin_plot( 160 plot_type=args.plot_type, 161 column1=args.column1, 162 column2=args.column2, 163 width=args.width, 164 height=args.height, 165 gridsize=args.gridsize, 166 scaling=args.scaling, 167 percentile=args.percentile, 168 verbose=args.verbose, 169 ) 170 logger.info("Plot created successfully") 171 except ValueError as e: 172 logger.error("Error creating plot: %s", e) 173 sys.exit(1)
Main function to parse arguments and create hexbin plot.