csa3d 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,13 @@
1
+ """Configuration package for CSA-3D.
2
+
3
+ Handles data paths, environment variables, and data loading.
4
+ """
5
+
6
+ from .settings import get_config, set_data_dir, get_data_dir, validate_config
7
+
8
+ __all__ = [
9
+ "get_config",
10
+ "set_data_dir",
11
+ "get_data_dir",
12
+ "validate_config",
13
+ ]
csa3d/config/loader.py ADDED
@@ -0,0 +1,290 @@
1
+ """Data loading utilities for CSA-3D.
2
+
3
+ Loads and caches data files required by CSA-3D.
4
+ """
5
+
6
+ import csv
7
+ import json
8
+ import warnings
9
+ from collections import defaultdict
10
+ from glob import glob
11
+ from pathlib import Path
12
+ from typing import Any, Dict, Set, Tuple
13
+
14
+ from .settings import _data_paths
15
+
16
+
17
+ def _load_json_mapping(file_path: Path) -> Dict[Any, Any]:
18
+ """Load a JSON file as a dictionary.
19
+
20
+ Args:
21
+ file_path: Path to JSON file
22
+
23
+ Returns:
24
+ Loaded JSON data
25
+
26
+ Raises:
27
+ FileNotFoundError: If file does not exist
28
+ ValueError: If JSON is invalid
29
+ """
30
+ if not file_path.exists():
31
+ raise FileNotFoundError(f"Data file not found: {file_path}")
32
+
33
+ try:
34
+ with open(file_path, "r") as f:
35
+ return json.load(f)
36
+ except json.JSONDecodeError as e:
37
+ raise ValueError(f"Invalid JSON in {file_path}: {e}")
38
+
39
+
40
+ def load_uniprot_pdb_mapping() -> Dict[str, list]:
41
+ """Load UniProt to PDB mapping from SIFTS.
42
+
43
+ Returns:
44
+ Dictionary mapping UniProt IDs to list of PDB IDs
45
+
46
+ Raises:
47
+ FileNotFoundError: If data file not found
48
+ """
49
+ path = _data_paths.get_path("uniprot_pdb_mapping")
50
+
51
+ if not path.exists():
52
+ raise FileNotFoundError(
53
+ f"UniProt-PDB mapping file not found: {path}\n"
54
+ "Run csa3d.config.setup_data() to download"
55
+ )
56
+
57
+ mapping = {}
58
+ with open(path, "r") as f:
59
+ next(f) # Skip header
60
+ for line in csv.reader(f):
61
+ if len(line) >= 2:
62
+ mapping[line[0]] = line[1].split(";")
63
+
64
+ return mapping
65
+
66
+
67
+ def load_pdb_uniprot_mapping() -> Dict[Tuple[str, str], str]:
68
+ """Load PDB to UniProt mapping from SIFTS.
69
+
70
+ Returns:
71
+ Dictionary mapping (PDB ID, chain) tuples to UniProt IDs
72
+
73
+ Raises:
74
+ FileNotFoundError: If data file not found
75
+ """
76
+ path = _data_paths.get_path("pdb_uniprot_mapping")
77
+
78
+ if not path.exists():
79
+ raise FileNotFoundError(
80
+ f"PDB-UniProt mapping file not found: {path}\n"
81
+ "Run csa3d.config.setup_data() to download"
82
+ )
83
+
84
+ mapping = {}
85
+ with open(path, "r") as f:
86
+ next(f) # Skip header
87
+ next(f) # Skip second header line
88
+ for line in csv.reader(f):
89
+ if len(line) >= 3:
90
+ mapping[(line[0], line[1])] = line[2]
91
+
92
+ return mapping
93
+
94
+
95
+ def load_pdb_ec_mapping() -> Dict[Tuple[str, str], str]:
96
+ """Load PDB to EC number mapping from SIFTS.
97
+
98
+ Returns:
99
+ Dictionary mapping (PDB ID, chain) tuples to EC numbers
100
+
101
+ Raises:
102
+ FileNotFoundError: If data file not found
103
+ """
104
+ path = _data_paths.get_path("pdb_ec_mapping")
105
+
106
+ if not path.exists():
107
+ raise FileNotFoundError(f"PDB-EC mapping file not found: {path}")
108
+
109
+ mapping = {}
110
+ with open(path, "r") as f:
111
+ next(f) # Skip header
112
+ for line in csv.reader(f):
113
+ if len(line) >= 4:
114
+ mapping[(line[0], line[1])] = line[3]
115
+
116
+ return mapping
117
+
118
+
119
+ def load_kegg_reactions() -> Dict[str, list]:
120
+ """Load KEGG reaction components mapping.
121
+
122
+ Returns:
123
+ Dictionary mapping EC numbers to reaction components
124
+
125
+ Raises:
126
+ FileNotFoundError: If data file not found
127
+ """
128
+ path = _data_paths.get_path("kegg_reactions")
129
+
130
+ if not path.exists():
131
+ raise FileNotFoundError(f"KEGG reactions file not found: {path}")
132
+
133
+ mapping = {}
134
+ with open(path, "r") as f:
135
+ for line in csv.reader(f):
136
+ if len(line) >= 2:
137
+ mapping[line[0]] = [line[1].split(";")]
138
+
139
+ return mapping
140
+
141
+
142
+ def load_rhea_reactions() -> Dict[str, list]:
143
+ """Load RHEA reaction components mapping.
144
+
145
+ Returns:
146
+ Dictionary mapping EC numbers to reaction components
147
+
148
+ Raises:
149
+ FileNotFoundError: If data file not found
150
+ """
151
+ path = _data_paths.get_path("rhea_reactions")
152
+
153
+ if not path.exists():
154
+ raise FileNotFoundError(f"RHEA reactions file not found: {path}")
155
+
156
+ mapping = {}
157
+ with open(path, "r") as f:
158
+ next(f) # Skip header
159
+ for line in csv.reader(f):
160
+ if len(line) >= 4:
161
+ mapping[line[2]] = line[3].split(";")
162
+
163
+ return mapping
164
+
165
+
166
+ def load_crystallization_artifacts() -> Set[str]:
167
+ """Load set of crystallization artifact HET codes.
168
+
169
+ Returns:
170
+ Set of HET codes that are crystallization artifacts
171
+
172
+ Raises:
173
+ FileNotFoundError: If data file not found
174
+ """
175
+ path = _data_paths.get_path("crystallization_hets")
176
+
177
+ if not path.exists():
178
+ raise FileNotFoundError(f"Crystallization HETs file not found: {path}")
179
+
180
+ artifacts = set()
181
+ with open(path, "r") as f:
182
+ for line in f:
183
+ artifacts.add(line.strip())
184
+
185
+ return artifacts
186
+
187
+
188
+ def load_ions() -> Tuple[Set[str], Set[str], Set[str]]:
189
+ """Load ion classifications.
190
+
191
+ Returns:
192
+ Tuple of (metals, reactive_nonmetals, noble_gases) sets
193
+
194
+ Raises:
195
+ FileNotFoundError: If data file not found
196
+ """
197
+ path = _data_paths.get_path("pdb_ions")
198
+
199
+ if not path.exists():
200
+ raise FileNotFoundError(f"PDB ions file not found: {path}")
201
+
202
+ metals = set()
203
+ reactive_nonmetals = set()
204
+ noble_gases = set()
205
+
206
+ with open(path, "r") as f:
207
+ next(f) # Skip header
208
+ for line in csv.reader(f):
209
+ if len(line) >= 4:
210
+ ion_type = line[3]
211
+ if ion_type == "METAL":
212
+ metals.add(line[0])
213
+ elif ion_type == "REACTIVE_NONMETAL":
214
+ reactive_nonmetals.add(line[0])
215
+ elif ion_type == "NOBLE_GAS":
216
+ noble_gases.add(line[0])
217
+
218
+ return metals, reactive_nonmetals, noble_gases
219
+
220
+
221
+ def load_pdb_cofactors() -> Dict[str, Set[str]]:
222
+ """Load PDB ID to cofactors mapping.
223
+
224
+ Returns:
225
+ Dictionary mapping PDB IDs to sets of cofactors
226
+
227
+ Raises:
228
+ FileNotFoundError: If data file not found
229
+ """
230
+ path = _data_paths.get_path("pdb_cofactors")
231
+
232
+ if not path.exists():
233
+ raise FileNotFoundError(f"PDB cofactors file not found: {path}")
234
+
235
+ cofactors = defaultdict(set)
236
+ with open(path, "r") as f:
237
+ next(f) # Skip header
238
+ for line in csv.reader(f, quotechar='"'):
239
+ if len(line) >= 5:
240
+ cofactors[line[0]].add(line[4])
241
+
242
+ return dict(cofactors)
243
+
244
+
245
+ def load_mcsa_cofactors() -> Dict[str, Set[str]]:
246
+ """Load M-CSA EC number to cofactors mapping.
247
+
248
+ Returns:
249
+ Dictionary mapping EC numbers to sets of cofactors
250
+
251
+ Raises:
252
+ FileNotFoundError: If data file not found
253
+ """
254
+ path = _data_paths.get_path("mcsa_cofactors")
255
+
256
+ if not path.exists():
257
+ raise FileNotFoundError(f"M-CSA cofactors file not found: {path}")
258
+
259
+ cofactors = defaultdict(set)
260
+ with open(path, "r") as f:
261
+ next(f) # Skip header
262
+ for line in csv.reader(f, quotechar='"'):
263
+ if len(line) >= 5:
264
+ for ec in line[4].split(";"):
265
+ cofactors[ec].add(line[1])
266
+
267
+ return dict(cofactors)
268
+
269
+
270
+ def load_pdb_resolution() -> Dict[str, str]:
271
+ """Load PDB resolution data.
272
+
273
+ Returns:
274
+ Dictionary mapping PDB IDs to resolution values
275
+
276
+ Raises:
277
+ FileNotFoundError: If data file not found
278
+ """
279
+ path = _data_paths.get_path("pdb_resolution")
280
+
281
+ if not path.exists():
282
+ raise FileNotFoundError(f"PDB resolution file not found: {path}")
283
+
284
+ resolution = {}
285
+ with open(path, "r") as f:
286
+ for line in csv.reader(f, delimiter=";"):
287
+ if len(line) >= 2:
288
+ resolution[line[0].strip().lower()] = line[1].strip()
289
+
290
+ return resolution
@@ -0,0 +1,218 @@
1
+ """Configuration settings for CSA-3D with environment variable support."""
2
+
3
+ import os
4
+ from pathlib import Path
5
+ from typing import Dict, Optional
6
+
7
+ # Default data directory locations to try
8
+ _DEFAULT_PATHS = [
9
+ "/Users/riziotis/ebi/phd/data",
10
+ "/nfs/research/thornton/riziotis/research/phd/data",
11
+ str(Path.home() / ".csa3d" / "data"),
12
+ ]
13
+
14
+
15
+ class ConfigError(Exception):
16
+ """Raised when configuration is invalid or incomplete."""
17
+
18
+ pass
19
+
20
+
21
+ class DataPaths:
22
+ """Manages data file paths for CSA-3D.
23
+
24
+ Paths can be configured via:
25
+ 1. Environment variable CSA3D_DATA_DIR
26
+ 2. Direct call to set_data_dir()
27
+ 3. Default locations
28
+ """
29
+
30
+ def __init__(self) -> None:
31
+ """Initialize data paths."""
32
+ self._data_dir: Optional[Path] = None
33
+ self._initialized = False
34
+
35
+ def set_data_dir(self, data_dir: str) -> None:
36
+ """Set the data directory explicitly.
37
+
38
+ Args:
39
+ data_dir: Path to directory containing CSA-3D data files
40
+
41
+ Raises:
42
+ ConfigError: If directory does not exist
43
+ """
44
+ path = Path(data_dir)
45
+ if not path.is_dir():
46
+ raise ConfigError(f"Data directory does not exist: {data_dir}")
47
+ self._data_dir = path
48
+ self._initialized = True
49
+
50
+ def get_data_dir(self) -> Path:
51
+ """Get the configured data directory.
52
+
53
+ Returns:
54
+ Path to data directory
55
+
56
+ Raises:
57
+ ConfigError: If no valid data directory is configured
58
+ """
59
+ if self._data_dir is not None:
60
+ return self._data_dir
61
+
62
+ # Try environment variable first
63
+ env_dir = os.environ.get("CSA3D_DATA_DIR")
64
+ if env_dir:
65
+ path = Path(env_dir)
66
+ if path.is_dir():
67
+ self._data_dir = path
68
+ self._initialized = True
69
+ return path
70
+ raise ConfigError(
71
+ f"CSA3D_DATA_DIR points to non-existent directory: {env_dir}"
72
+ )
73
+
74
+ # Try default locations
75
+ for default_path in _DEFAULT_PATHS:
76
+ path = Path(default_path)
77
+ if path.is_dir():
78
+ self._data_dir = path
79
+ self._initialized = True
80
+ return path
81
+
82
+ # No valid path found
83
+ raise ConfigError(
84
+ "No CSA-3D data directory found. "
85
+ "Please either:\n"
86
+ " 1. Set environment variable: export CSA3D_DATA_DIR=/path/to/data\n"
87
+ " 2. Call: csa3d.config.set_data_dir('/path/to/data')\n"
88
+ " 3. Run: csa3d.config.setup_data() to download datasets\n"
89
+ f"Searched in: {', '.join(_DEFAULT_PATHS)}"
90
+ )
91
+
92
+ def validate(self) -> bool:
93
+ """Validate that all required data files exist.
94
+
95
+ Returns:
96
+ True if configuration is valid
97
+
98
+ Raises:
99
+ ConfigError: If required files are missing
100
+ """
101
+ data_dir = self.get_data_dir()
102
+ required_files = [
103
+ "mcsa/catalytic_residues_homologues.json",
104
+ "mcsa/catalytic_residues_references.json",
105
+ "sifts/uniprot_pdb.csv",
106
+ "sifts/pdb_chain_uniprot.csv",
107
+ "sifts/pdb_chain_enzyme.csv",
108
+ ]
109
+
110
+ missing = []
111
+ for rel_path in required_files:
112
+ full_path = data_dir / rel_path
113
+ if not full_path.exists():
114
+ missing.append(rel_path)
115
+
116
+ if missing:
117
+ raise ConfigError(
118
+ f"Missing required data files in {data_dir}:\n"
119
+ + "\n".join(f" - {f}" for f in missing)
120
+ + "\nRun: csa3d.config.setup_data() to download"
121
+ )
122
+ return True
123
+
124
+ def get_path(self, key: str) -> Path:
125
+ """Get path to a specific data file.
126
+
127
+ Args:
128
+ key: File identifier (e.g., 'catalytic_residues', 'pdb_assemblies')
129
+
130
+ Returns:
131
+ Path to the file
132
+
133
+ Raises:
134
+ ConfigError: If file key is unknown
135
+ """
136
+ data_dir = self.get_data_dir()
137
+
138
+ paths = {
139
+ "catalytic_residues": data_dir / "mcsa" / "catalytic_residues_homologues.json",
140
+ "catalytic_residues_references": data_dir / "mcsa" / "catalytic_residues_references.json",
141
+ "mcsa_entry_info": data_dir / "mcsa" / "entry_info" / "mcsa_entry_info.*.json",
142
+ "pdb_assemblies": data_dir / "pdbe" / "assembly_cif" / "cif",
143
+ "kegg_molecules": data_dir / "kegg" / "sdf",
144
+ "chebi_molecules": data_dir / "chebi" / "sdf",
145
+ "pdbe_het_molecules": data_dir / "pdbe" / "het_sdf",
146
+ "uniprot_pdb_mapping": data_dir / "sifts" / "uniprot_pdb.csv",
147
+ "pdb_uniprot_mapping": data_dir / "sifts" / "pdb_chain_uniprot.csv",
148
+ "pdb_ec_mapping": data_dir / "sifts" / "pdb_chain_enzyme.csv",
149
+ "kegg_reactions": data_dir / "kegg" / "kegg_reaction_components.csv",
150
+ "rhea_reactions": data_dir / "rhea" / "rhea_reaction_components.csv",
151
+ "pdb_ions": data_dir / "pdbe" / "pdb_ions.csv",
152
+ "pdb_cofactors": data_dir / "pdbe" / "pdb_cofactors.csv",
153
+ "mcsa_cofactors": data_dir / "mcsa" / "mcsa_cofactors.csv",
154
+ "crystallization_hets": data_dir / "pdbe" / "crystallization_hets.csv",
155
+ "pdb_resolution": data_dir / "pdbe" / "resolu.idx",
156
+ }
157
+
158
+ if key not in paths:
159
+ raise ConfigError(
160
+ f"Unknown path key: {key}. "
161
+ f"Valid keys: {', '.join(paths.keys())}"
162
+ )
163
+
164
+ return paths[key]
165
+
166
+
167
+ # Global instance
168
+ _data_paths = DataPaths()
169
+
170
+
171
+ def get_config() -> Dict[str, Path]:
172
+ """Get current configuration as dictionary.
173
+
174
+ Returns:
175
+ Dictionary of configuration values
176
+ """
177
+ data_dir = _data_paths.get_data_dir()
178
+ return {
179
+ "data_dir": data_dir,
180
+ "catalytic_residues": _data_paths.get_path("catalytic_residues"),
181
+ "pdb_assemblies": _data_paths.get_path("pdb_assemblies"),
182
+ }
183
+
184
+
185
+ def set_data_dir(data_dir: str) -> None:
186
+ """Set the CSA-3D data directory.
187
+
188
+ Args:
189
+ data_dir: Path to directory containing CSA-3D data files
190
+
191
+ Raises:
192
+ ConfigError: If directory does not exist
193
+ """
194
+ _data_paths.set_data_dir(data_dir)
195
+
196
+
197
+ def get_data_dir() -> str:
198
+ """Get the current CSA-3D data directory.
199
+
200
+ Returns:
201
+ Path to data directory as string
202
+
203
+ Raises:
204
+ ConfigError: If no valid configuration found
205
+ """
206
+ return str(_data_paths.get_data_dir())
207
+
208
+
209
+ def validate_config() -> bool:
210
+ """Validate current configuration.
211
+
212
+ Returns:
213
+ True if all required data files exist
214
+
215
+ Raises:
216
+ ConfigError: If configuration is invalid
217
+ """
218
+ return _data_paths.validate()
@@ -0,0 +1,422 @@
1
+ Metadata-Version: 2.4
2
+ Name: csa3d
3
+ Version: 0.2.0
4
+ Summary: Extract and analyze enzyme catalytic sites in 3D from the Mechanism and Catalytic Site Atlas (M-CSA)
5
+ Author-email: Ioannis Riziotis <riziotis@ebi.ac.uk>
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/your-username/csa3d
8
+ Project-URL: Documentation, https://csa3d.readthedocs.io
9
+ Project-URL: Repository, https://github.com/your-username/csa3d
10
+ Project-URL: Issue Tracker, https://github.com/your-username/csa3d/issues
11
+ Keywords: enzymes,catalysis,structural-biology,M-CSA,active-sites
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
22
+ Classifier: Topic :: Scientific/Engineering :: Chemistry
23
+ Requires-Python: >=3.8
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: biopython>=1.81
27
+ Requires-Dist: numpy>=1.21.0
28
+ Requires-Dist: pandas>=1.3.0
29
+ Requires-Dist: scipy>=1.7.0
30
+ Requires-Dist: scikit-learn>=0.24.0
31
+ Requires-Dist: rdkit>=2021.09.0
32
+ Requires-Dist: natsort>=8.0.0
33
+ Requires-Dist: dendrogram-cut>=0.1.0
34
+ Requires-Dist: parity-core>=0.5.0
35
+ Requires-Dist: rmsd>=1.4.0
36
+ Provides-Extra: dev
37
+ Requires-Dist: pytest>=7.0; extra == "dev"
38
+ Requires-Dist: pytest-cov>=4.0; extra == "dev"
39
+ Requires-Dist: black>=23.0; extra == "dev"
40
+ Requires-Dist: isort>=5.12; extra == "dev"
41
+ Requires-Dist: flake8>=6.0; extra == "dev"
42
+ Requires-Dist: mypy>=1.0; extra == "dev"
43
+ Requires-Dist: types-setuptools; extra == "dev"
44
+ Requires-Dist: types-requests; extra == "dev"
45
+ Provides-Extra: docs
46
+ Requires-Dist: sphinx>=6.0; extra == "docs"
47
+ Requires-Dist: sphinx-rtd-theme>=1.2; extra == "docs"
48
+ Requires-Dist: myst-parser>=0.19; extra == "docs"
49
+ Provides-Extra: examples
50
+ Requires-Dist: jupyter>=1.0; extra == "examples"
51
+ Requires-Dist: notebook>=6.0; extra == "examples"
52
+ Requires-Dist: matplotlib>=3.5; extra == "examples"
53
+ Dynamic: license-file
54
+
55
+ # CSA-3D: 3D Analysis of Enzyme Catalytic Sites
56
+
57
+ A Python package for extracting, analyzing, and manipulating enzyme catalytic sites in three dimensions from the **Mechanism and Catalytic Site Atlas (M-CSA)** hosted at [EMBL-EBI](https://www.ebi.ac.uk/thornton-srv/m-csa/).
58
+
59
+ ## What is CSA-3D?
60
+
61
+ CSA-3D enables computational biochemists and structural biologists to:
62
+
63
+ - **Extract** catalytic site geometries from PDB structures and UniProt sequences
64
+ - **Compare** active sites across homologous proteins using RMSD clustering
65
+ - **Create** structure templates for enzyme active sites with geometric constraints
66
+ - **Analyze** ligand proximity and chemical similarity in active sites
67
+ - **Visualize** and export catalytic site information in multiple formats
68
+
69
+ This package was developed to support research on enzyme mechanisms and is particularly useful for:
70
+ - Comparative structural analysis of enzyme families
71
+ - Active site template generation for molecular docking
72
+ - Catalytic site conservation studies
73
+ - Structure-guided annotation of enzyme function
74
+
75
+ **See also**: [CSA-3D paper](https://www.sciencedirect.com/science/article/pii/S0022283622000912)
76
+
77
+ ## Installation
78
+
79
+ ### Requirements
80
+
81
+ - Python 3.8 or higher
82
+ - ~50 GB of disk space for complete M-CSA dataset (can work with subsets)
83
+
84
+ ### Installation from PyPI
85
+
86
+ ```bash
87
+ pip install csa3d
88
+ ```
89
+
90
+ ### Installation from Source
91
+
92
+ ```bash
93
+ git clone https://github.com/your-username/csa3d.git
94
+ cd csa3d
95
+ pip install -e ".[dev]"
96
+ ```
97
+
98
+ ### Development Installation
99
+
100
+ For development with testing and documentation tools:
101
+
102
+ ```bash
103
+ pip install -e ".[dev,docs]"
104
+ ```
105
+
106
+ ## Quick Start
107
+
108
+ ### 1. Configure Data Directory
109
+
110
+ First, you need to set up the M-CSA data files. You can either:
111
+
112
+ **Option A: Download automatically (recommended)**
113
+ ```python
114
+ from csa3d import config
115
+ config.setup_data("/path/to/csa3d_data") # Downloads ~50 GB
116
+ ```
117
+
118
+ **Option B: Set environment variable**
119
+ ```bash
120
+ export CSA3D_DATA_DIR="/path/to/csa3d_data"
121
+ ```
122
+
123
+ **Option C: Set in code**
124
+ ```python
125
+ from csa3d import config
126
+ config.set_data_dir("/path/to/csa3d_data")
127
+ ```
128
+
129
+ ### 2. Load and Inspect Active Sites
130
+
131
+ ```python
132
+ from csa3d import Mcsa
133
+
134
+ # Initialize the database
135
+ db = Mcsa()
136
+
137
+ # Build a specific entry (e.g., M-CSA ID 1)
138
+ db.build(entry_ids=1, annotate=True)
139
+
140
+ # Iterate over entries
141
+ for entry in db:
142
+ print(f"Entry {entry.mcsa_id}: {len(entry.pdbsites)} PDB sites")
143
+
144
+ # Get information
145
+ print(f" EC Number: {entry.info['ec']}")
146
+ print(f" Enzyme: {entry.info['enzyme_name']}")
147
+
148
+ # Inspect active sites
149
+ for site in entry.get_pdbsites(sane_only=True):
150
+ print(f" PDB: {site.pdb_id}, {len(site.residues)} residues")
151
+ print(f" Resolution: {site.resolution} Å")
152
+ ```
153
+
154
+ ### 3. Clustering and Template Creation
155
+
156
+ ```python
157
+ # Build multiple entries
158
+ db.build(entry_ids=[1, 2, 3], annotate=True)
159
+ entry = db.entries[1]
160
+
161
+ # Calculate RMSD between all active sites
162
+ sites = list(entry.get_pdbsites(sane_only=True))
163
+ rmsd_matrix = entry.rmsd_matrix(sites)
164
+
165
+ # Cluster sites by similarity
166
+ clusters = entry.clustering(rmsd_matrix, height=1.5)
167
+
168
+ print(f"Found {len(clusters)} clusters")
169
+ for cluster_id, site_ids in clusters.items():
170
+ print(f" Cluster {cluster_id}: {len(site_ids)} sites")
171
+
172
+ # Create a template from conserved sites
173
+ template = entry.create_template(outdir="./templates")
174
+ print(f"Template created: {template.id}")
175
+ ```
176
+
177
+ ## Data Requirements
178
+
179
+ CSA-3D requires data from several external sources:
180
+
181
+ ### Core M-CSA Data
182
+ - `mcsa/catalytic_residues_homologues.json` - Homologous catalytic residues
183
+ - `mcsa/catalytic_residues_references.json` - Reference catalytic residues
184
+ - `mcsa/entry_info/mcsa_entry_info.*.json` - Entry metadata
185
+
186
+ ### PDB Data
187
+ - `pdbe/assembly_cif/cif/` - PDB assembly structures (mmCIF format)
188
+ - `pdbe/pdb_ions.csv` - Ion classification
189
+ - `pdbe/pdb_cofactors.csv` - Cofactor information
190
+ - `pdbe/crystallization_hets.csv` - Crystallization artifacts
191
+
192
+ ### Sequence/Mapping Data (SIFTS)
193
+ - `sifts/uniprot_pdb.csv` - UniProt to PDB mapping
194
+ - `sifts/pdb_chain_uniprot.csv` - PDB to UniProt mapping
195
+ - `sifts/pdb_chain_enzyme.csv` - PDB to EC number mapping
196
+
197
+ ### Reaction Data
198
+ - `kegg/kegg_reaction_components.csv` - KEGG enzyme reactions
199
+ - `rhea/rhea_reaction_components.csv` - RHEA reactions
200
+ - `pdbe/resolu.idx` - PDB resolution index
201
+
202
+ ### Molecule Data
203
+ - `kegg/sdf/` - KEGG small molecules
204
+ - `chebi/sdf/` - ChEBI compounds
205
+ - `pdbe/het_sdf/` - PDB heteroatom structures
206
+
207
+ To download all data:
208
+ ```python
209
+ from csa3d.config import setup_data
210
+ setup_data("/path/to/csa3d_data")
211
+ ```
212
+
213
+ Alternatively, download manually from:
214
+ - M-CSA: https://www.ebi.ac.uk/thornton-srv/m-csa/download/
215
+ - PDBe: https://www.ebi.ac.uk/pdbe/download/
216
+ - SIFTS: https://www.ebi.ac.uk/pdbe/docs/sifts/
217
+ - KEGG: https://www.kegg.jp/
218
+ - RHEA: https://www.rhea-db.org/
219
+
220
+ ## Usage Examples
221
+
222
+ ### Comparing Two Active Sites
223
+
224
+ ```python
225
+ from csa3d import Mcsa
226
+
227
+ db = Mcsa()
228
+ db.build(entry_ids=1)
229
+ entry = db.entries[1]
230
+
231
+ sites = list(entry.get_pdbsites(sane_only=True))
232
+ if len(sites) >= 2:
233
+ site1, site2 = sites[0], sites[1]
234
+
235
+ # Structural alignment
236
+ rotation, translation, rmsd_ca, rmsd_all = site1.fit(site2, weighted=True)
237
+ print(f"RMSD (backbone): {rmsd_ca:.2f} Å")
238
+ print(f"RMSD (all atoms): {rmsd_all:.2f} Å")
239
+ ```
240
+
241
+ ### Writing Templates for Docking
242
+
243
+ ```python
244
+ # Create template with specific parameters
245
+ template = entry.create_template(
246
+ ca=False, # Use all heavy atoms
247
+ outdir="./templates",
248
+ outfile="myenzyme.template.pdb",
249
+ all_fuzzy=False, # Use conservative fuzzy matching
250
+ no_alt=False # Include alternative residue options
251
+ )
252
+
253
+ # Template can be used with docking software like TESS/Jess
254
+ ```
255
+
256
+ ### Batch Processing
257
+
258
+ ```python
259
+ from csa3d import Mcsa
260
+
261
+ db = Mcsa()
262
+
263
+ # Build all entries (takes time)
264
+ entry_ids = list(db.catalytic_residue_info.keys())
265
+ db.build(entry_ids=entry_ids[:10], verbose=True) # First 10
266
+
267
+ # Analyze
268
+ for entry in db:
269
+ n_sites = len(entry.pdbsites)
270
+ n_clusters = len(entry.clustering(entry.rmsd_matrix(list(entry.get_pdbsites()))))
271
+ print(f"{entry.mcsa_id}: {n_sites} sites, {n_clusters} clusters")
272
+ ```
273
+
274
+ ## Key Classes
275
+
276
+ ### Mcsa
277
+ Main database class. Load and manage M-CSA entries.
278
+ ```python
279
+ db = Mcsa()
280
+ db.build(entry_ids=1) # Build specific entry
281
+ entry = db.entries[1] # Access Entry object
282
+ ```
283
+
284
+ ### Entry
285
+ Represents one M-CSA entry containing PDB and UniProt active sites.
286
+ ```python
287
+ entry.pdbsites # List of PdbSite objects
288
+ entry.unisites # List of UniSite objects
289
+ entry.create_template() # Generate template
290
+ entry.clustering() # RMSD-based clustering
291
+ ```
292
+
293
+ ### PdbSite
294
+ A catalytic site from a PDB structure.
295
+ ```python
296
+ site.pdb_id # PDB identifier
297
+ site.residues # Catalytic residues
298
+ site.ligands # Proximal ligands
299
+ site.fit(other_site) # Structural alignment
300
+ ```
301
+
302
+ ### UniSite
303
+ A catalytic site from UniProt sequence.
304
+ ```python
305
+ site.uniprot_id # UniProt accession
306
+ site.residues # Catalytic residues
307
+ ```
308
+
309
+ ## Configuration
310
+
311
+ ### Environment Variables
312
+
313
+ - `CSA3D_DATA_DIR` - Path to M-CSA data directory (default: auto-detect)
314
+
315
+ ### Configuration File
316
+
317
+ Create `~/.csa3d/config.yml`:
318
+ ```yaml
319
+ data_dir: /path/to/csa3d_data
320
+ ```
321
+
322
+ ### In Code
323
+
324
+ ```python
325
+ from csa3d import config
326
+
327
+ config.set_data_dir("/path/to/data")
328
+ config.validate_config() # Check if valid
329
+ print(config.get_data_dir())
330
+ ```
331
+
332
+ ## Documentation
333
+
334
+ - [Architecture Guide](docs/architecture.md) - System design and data flow
335
+ - [API Reference](https://csa3d.readthedocs.io) - Full API documentation
336
+ - [Examples](examples/) - Jupyter notebooks and scripts
337
+
338
+ ## Testing
339
+
340
+ Run tests with pytest:
341
+ ```bash
342
+ pytest tests/
343
+ ```
344
+
345
+ Run with coverage:
346
+ ```bash
347
+ pytest --cov=csa3d tests/
348
+ ```
349
+
350
+ ## Performance Considerations
351
+
352
+ - **First run** is slow (~minutes) as PDB structures are parsed and cached
353
+ - **RMSD clustering** on large site sets can be memory-intensive
354
+ - **Template creation** involves fitting multiple structures (depends on cluster size)
355
+
356
+ Tips:
357
+ - Use `sane_only=True` to filter low-quality sites
358
+ - Process entries in batches
359
+ - Use `resolution_cutoff` to filter low-resolution structures
360
+ - Cache parsed entries with pickle for reuse
361
+
362
+ ## Citation
363
+
364
+ If you use CSA-3D in your research, please cite:
365
+
366
+ ```bibtex
367
+ @article{Riziotis2022,
368
+ title={CSA-3D: {A} framework to manipulate enzyme catalytic sites in three dimensions},
369
+ author={Riziotis, Ioannis and others},
370
+ journal={Journal of Molecular Biology},
371
+ volume={434},
372
+ number={5},
373
+ pages={167488},
374
+ year={2022},
375
+ issn={0022-2836},
376
+ doi={10.1016/j.jmb.2022.167488},
377
+ url={https://www.sciencedirect.com/science/article/pii/S0022283622000912}
378
+ }
379
+ ```
380
+
381
+ ## Contributing
382
+
383
+ Contributions are welcome! Please:
384
+
385
+ 1. Fork the repository
386
+ 2. Create a feature branch: `git checkout -b feature/my-feature`
387
+ 3. Make changes and add tests
388
+ 4. Run quality checks: `make lint`
389
+ 5. Submit a pull request
390
+
391
+ ## Issues & Support
392
+
393
+ - **Bug reports**: [GitHub Issues](https://github.com/your-username/csa3d/issues)
394
+ - **Questions**: Create a discussion or post an issue
395
+ - **Feature requests**: Open an issue with `[FEATURE]` prefix
396
+
397
+ ## License
398
+
399
+ Apache License 2.0 - see LICENSE file for details
400
+
401
+ ## Contact
402
+
403
+ - **Author**: Ioannis Riziotis
404
+ - **Email**: riziotis@ebi.ac.uk
405
+ - **Affiliation**: EMBL-EBI, Wellcome Trust Genome Campus, Cambridge, UK
406
+
407
+ ## Acknowledgments
408
+
409
+ CSA-3D is built on top of several excellent packages:
410
+ - [Biopython](https://biopython.org/) - Biological computation
411
+ - [NumPy](https://numpy.org/) - Numerical computing
412
+ - [SciPy](https://scipy.org/) - Scientific computing
413
+ - [scikit-learn](https://scikit-learn.org/) - Machine learning
414
+ - [RDKit](https://www.rdkit.org/) - Cheminformatics
415
+
416
+ ## Changelog
417
+
418
+ See [CHANGELOG.md](CHANGELOG.md) for version history and breaking changes.
419
+
420
+ ---
421
+
422
+ **Questions?** See [docs/faq.md](docs/faq.md) or open an issue.
@@ -0,0 +1,8 @@
1
+ csa3d/config/__init__.py,sha256=BxCHYnrzkdMPMof8a0mg0dxD8kehXqtq4m-d9ofApLA,278
2
+ csa3d/config/loader.py,sha256=R9ZOIJHUTYbPKZWpvxAr647e5dTY-2g-zwCQa7BQR-Q,7591
3
+ csa3d/config/settings.py,sha256=py2nZxOymZv1nSBVTxmpIlT-RlTHzE4i-WXuELeDULQ,6704
4
+ csa3d-0.2.0.dist-info/licenses/LICENSE,sha256=NXn2B_GTwWQMeoG4INqSiXR-PW6m6HpLPSgmr3vXMUE,10289
5
+ csa3d-0.2.0.dist-info/METADATA,sha256=vAbOv9Oxb4UeV2tbQfEe2zN7j85Q_A53GNTKjEZMUy4,12133
6
+ csa3d-0.2.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
7
+ csa3d-0.2.0.dist-info/top_level.txt,sha256=ESGt81ShErdbujT7-D3RcXmBzbF5g5zm4J7HQYRFlPs,6
8
+ csa3d-0.2.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,180 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined in Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
24
+ permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or Object
36
+ form, made available under the License, as indicated by a copyright
37
+ notice that is included in or attached to the work (an example is
38
+ provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship, thus including
44
+ but not limited to any software source code, documentation source,
45
+ and configuration files, and any object code generated from such
46
+ Source form (and excluding any modifications made for the purpose of
47
+ understanding or correcting errors or deficiencies in the Work or
48
+ for other reasons that would not be considered original works of
49
+ authorship, such as mere reformatting).
50
+
51
+ "Contribution" shall mean any work of authorship, including
52
+ the original Work and any Derivative Works thereof, that is
53
+ intentionally submitted to, or received by, Licensor for inclusion
54
+ in the Work by the copyright owner or by an individual or Legal
55
+ Entity authorized to submit on behalf of the copyright owner. For
56
+ the purposes of this definition, "submitted" means any form of
57
+ electronic, verbal, or written communication sent by or on behalf
58
+ of a party, including but not limited to communication on electronic
59
+ mailing lists, source code control systems, and issue tracking
60
+ systems that are managed by, or on behalf of, the Licensor for the
61
+ purpose of discussing and improving the Work, but excluding
62
+ communication that is conspicuously marked or otherwise designated
63
+ in writing by the copyright owner as "Not a Contribution."
64
+
65
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
66
+ whom a Contribution has been received by Licensor and subsequently
67
+ incorporated within the Work.
68
+
69
+ 2. Grant of Copyright License. Subject to the terms and conditions of
70
+ this License, each Contributor hereby grants to You a perpetual,
71
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
72
+ copyright license to reproduce, prepare Derivative Works of,
73
+ publicly display, publicly perform, sublicense, and distribute the
74
+ Work and such Derivative Works in Source or Object form.
75
+
76
+ 3. Grant of Patent License. Subject to the terms and conditions of
77
+ this License, each Contributor hereby grants to You a perpetual,
78
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
79
+ (except as stated in this section) patent license to make, have made,
80
+ use, offer to sell, sell, import, and otherwise transfer the Work,
81
+ where such license applies only to those patent claims licensable
82
+ by such Contributor that are necessarily infringed by their
83
+ Contribution(s) alone or by combination of their Contribution(s)
84
+ with the Work to which such Contribution(s) was submitted. If You
85
+ institute patent litigation against any entity (including a
86
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
87
+ or a Contribution incorporated within the Work constitutes direct
88
+ or contributory patent infringement, then any patent licenses
89
+ granted to You under this License for that Work shall terminate
90
+ as of the date such litigation is filed.
91
+
92
+ 4. Redistribution. You may reproduce and distribute copies of the
93
+ Work or Derivative Works thereof in any medium, with or without
94
+ modifications, and in Source or Object form, provided that You
95
+ meet the following conditions:
96
+
97
+ (a) You must give any other recipients of the Work or
98
+ Derivative Works a copy of this License; and
99
+
100
+ (b) You must cause any modified files to carry prominent notices
101
+ stating that You changed the files; and
102
+
103
+ (c) You must retain, in the Source form of any Derivative Works
104
+ that You distribute, all copyright, patent, trademark, and
105
+ attribution notices from the Source form of the Work,
106
+ excluding those notices that do not pertain to any part of
107
+ the Derivative Works; and
108
+
109
+ (d) If the Work includes a "NOTICE" text file, then any
110
+ Derivative Works that You distribute must include a readable
111
+ copy of the attribution notices contained
112
+ within such NOTICE file, excluding those notices that do not
113
+ pertain to any part of the Derivative Works, in at least one
114
+ of the following places: within a NOTICE text file distributed
115
+ as part of the Derivative Works; within the Source form or
116
+ documentation, if provided along with the Derivative Works; or,
117
+ within a display generated by the Derivative Works, if and
118
+ wherever such third-party notices normally appear. The contents
119
+ of the NOTICE file are for informational purposes only and
120
+ do not modify the License. You may add Your own attribution
121
+ notices within Derivative Works that You distribute, alongside
122
+ or as an addendum to the NOTICE from the Work, provided that
123
+ such additional attribution notices cannot be construed
124
+ as modifying the License.
125
+
126
+ You may add Your own copyright statement to Your modifications and
127
+ may provide additional or different license terms and conditions
128
+ for use, reproduction, or distribution of Your modifications, or
129
+ for any such Derivative Works as a whole, provided Your use,
130
+ reproduction, and distribution of the Work otherwise complies with
131
+ the conditions of this License.
132
+
133
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
134
+ any Contribution intentionally submitted for inclusion in the Work
135
+ by You to Licensor shall be under the terms and conditions of
136
+ this License, without limitation of any additional terms or
137
+ conditions.
138
+ Notwithstanding the above, nothing herein shall supersede or modify
139
+ the terms of any separate license agreement you may have executed
140
+ with Licensor regarding such Contribution.
141
+
142
+ 6. Trademarks. This License does not grant permission to use the trade
143
+ names, trademarks, service marks, or product names of the Licensor,
144
+ except as required for reasonable and customary use in describing the
145
+ origin of the Work and reproducing the content of the NOTICE file.
146
+
147
+ 7. Disclaimer of Warranty. Unless required by applicable law or
148
+ agreed to in writing, Licensor provides the Work (and each
149
+ Contributor provides its Contributions) on an "AS IS" BASIS,
150
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
151
+ implied, including, without limitation, any warranties or conditions
152
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
153
+ PARTICULAR PURPOSE. You are solely responsible for determining the
154
+ appropriateness of using or redistributing the Work and assume any
155
+ risks associated with Your exercise of permissions under this License.
156
+
157
+ 8. Limitation of Liability. In no event and under no legal theory,
158
+ whether in tort (including negligence), contract, or otherwise,
159
+ unless required by applicable law (such as deliberate and grossly
160
+ negligent acts) or agreed to in writing, shall any Contributor be
161
+ liable to You for damages, including any direct, indirect, special,
162
+ incidental, or consequential damages of any character arising as a
163
+ result of this License or out of the use or inability to use the
164
+ Work (including but not limited to damages for loss of goodwill,
165
+ work stoppage, computer failure or malfunction, or any and all
166
+ other commercial damages or losses), even if such Contributor
167
+ has been advised of the possibility of such damages.
168
+
169
+ 9. Accepting Warranty or Additional Liability. While redistributing
170
+ the Work or Derivative Works thereof, You may choose to offer,
171
+ and charge a fee for, acceptance of support, warranty, indemnity,
172
+ or other liability obligations and/or rights consistent with this
173
+ License. However, in accepting such obligations, You may act only
174
+ on Your own behalf and on Your sole responsibility, not on behalf
175
+ of any other Contributor, and only if You agree to indemnify,
176
+ defend, and hold each Contributor harmless for any liability
177
+ incurred by, or claims asserted against, such Contributor by reason
178
+ of your accepting any such warranty or additional liability.
179
+
180
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1 @@
1
+ csa3d