Datasets:
Add normalized Parquet train/test PDB CCD table
Browse files- README.md +181 -0
- data/test-00000-of-00001.parquet +3 -0
- data/train-00000-of-00001.parquet +3 -0
- dataset_summary.json +195 -0
- scripts/prepare_pdb_ccd_dataset.py +443 -0
README.md
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
pretty_name: PDB Chemical Component Dictionary
|
| 3 |
+
license: other
|
| 4 |
+
tags:
|
| 5 |
+
- biology
|
| 6 |
+
- chemistry
|
| 7 |
+
- structural-biology
|
| 8 |
+
- pdb
|
| 9 |
+
- chemical-components
|
| 10 |
+
- mmcif
|
| 11 |
+
- parquet
|
| 12 |
+
configs:
|
| 13 |
+
- config_name: default
|
| 14 |
+
data_files:
|
| 15 |
+
- split: train
|
| 16 |
+
path: data/train-*.parquet
|
| 17 |
+
- split: test
|
| 18 |
+
path: data/test-*.parquet
|
| 19 |
+
---
|
| 20 |
+
|
| 21 |
+
# PDB Chemical Component Dictionary
|
| 22 |
+
|
| 23 |
+
This dataset contains a viewer-friendly Parquet table derived from the PDB Chemical Component Dictionary file in this repository. Each row is one chemical component from `components.cif.gz`.
|
| 24 |
+
|
| 25 |
+
The original source file remains in the repository. The default `datasets` configuration uses the normalized Parquet files under `data/` so that the Hugging Face Dataset Viewer and `load_dataset()` can read component records directly.
|
| 26 |
+
|
| 27 |
+
## Splits
|
| 28 |
+
|
| 29 |
+
The split is deterministic by component identifier: `sha256(component_id) % 10`. Bucket `0` is `test`; buckets `1` through `9` are `train`.
|
| 30 |
+
|
| 31 |
+
| Split | Rows |
|
| 32 |
+
|---|---:|
|
| 33 |
+
| train | 45,045 |
|
| 34 |
+
| test | 5,009 |
|
| 35 |
+
| total | 50,054 |
|
| 36 |
+
|
| 37 |
+
## Dataset Statistics
|
| 38 |
+
|
| 39 |
+
| Field | Value |
|
| 40 |
+
|---|---:|
|
| 41 |
+
| Components | 50,054 |
|
| 42 |
+
| Released components | 49,292 |
|
| 43 |
+
| Obsolete components | 762 |
|
| 44 |
+
| Components with atoms | 49,947 |
|
| 45 |
+
| Components with bonds | 49,921 |
|
| 46 |
+
| Components with descriptors | 50,052 |
|
| 47 |
+
| Components with identifiers | 37,058 |
|
| 48 |
+
| Components with PCM annotations | 613 |
|
| 49 |
+
| Latest modified date in source | `2026-04-24` |
|
| 50 |
+
|
| 51 |
+
| Common component type | Rows |
|
| 52 |
+
|---|---:|
|
| 53 |
+
| NON-POLYMER | 26,117 |
|
| 54 |
+
| non-polymer | 19,493 |
|
| 55 |
+
| L-PEPTIDE LINKING | 923 |
|
| 56 |
+
| L-peptide linking | 580 |
|
| 57 |
+
| peptide-like | 556 |
|
| 58 |
+
| D-saccharide | 405 |
|
| 59 |
+
| DNA LINKING | 325 |
|
| 60 |
+
| RNA LINKING | 223 |
|
| 61 |
+
|
| 62 |
+
## Usage
|
| 63 |
+
|
| 64 |
+
Install the Hugging Face Datasets library:
|
| 65 |
+
|
| 66 |
+
```bash
|
| 67 |
+
pip install datasets
|
| 68 |
+
```
|
| 69 |
+
|
| 70 |
+
Load all splits:
|
| 71 |
+
|
| 72 |
+
```python
|
| 73 |
+
from datasets import load_dataset
|
| 74 |
+
|
| 75 |
+
ds = load_dataset("LiteFold/PDB-CCD")
|
| 76 |
+
print(ds)
|
| 77 |
+
|
| 78 |
+
row = ds["train"][0]
|
| 79 |
+
print(row["component_id"], row["name"], row["formula"])
|
| 80 |
+
```
|
| 81 |
+
|
| 82 |
+
Load one split:
|
| 83 |
+
|
| 84 |
+
```python
|
| 85 |
+
from datasets import load_dataset
|
| 86 |
+
|
| 87 |
+
train = load_dataset("LiteFold/PDB-CCD", split="train")
|
| 88 |
+
test = load_dataset("LiteFold/PDB-CCD", split="test")
|
| 89 |
+
```
|
| 90 |
+
|
| 91 |
+
Stream rows without downloading the full table first:
|
| 92 |
+
|
| 93 |
+
```python
|
| 94 |
+
from datasets import load_dataset
|
| 95 |
+
|
| 96 |
+
stream = load_dataset("LiteFold/PDB-CCD", split="train", streaming=True)
|
| 97 |
+
for row in stream.take(5):
|
| 98 |
+
print(row["component_id"], row["canonical_smiles"], row["atom_count"])
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
Filter released non-polymer components with InChIKeys:
|
| 102 |
+
|
| 103 |
+
```python
|
| 104 |
+
from datasets import load_dataset
|
| 105 |
+
|
| 106 |
+
ds = load_dataset("LiteFold/PDB-CCD", split="train")
|
| 107 |
+
released = ds.filter(
|
| 108 |
+
lambda row: row["release_status"] == "REL"
|
| 109 |
+
and row["component_type"] in {"NON-POLYMER", "non-polymer"}
|
| 110 |
+
and row["inchikey"] is not None
|
| 111 |
+
)
|
| 112 |
+
print(released[0])
|
| 113 |
+
```
|
| 114 |
+
|
| 115 |
+
Find components modified after a date:
|
| 116 |
+
|
| 117 |
+
```python
|
| 118 |
+
from datasets import load_dataset
|
| 119 |
+
|
| 120 |
+
ds = load_dataset("LiteFold/PDB-CCD", split="train")
|
| 121 |
+
recent = ds.filter(lambda row: row["modified_date"] is not None and row["modified_date"] >= "2026-01-01")
|
| 122 |
+
print(recent[0]["component_id"], recent[0]["modified_date"])
|
| 123 |
+
```
|
| 124 |
+
|
| 125 |
+
## Columns
|
| 126 |
+
|
| 127 |
+
| Column | Description |
|
| 128 |
+
|---|---|
|
| 129 |
+
| `component_id` | Chemical component identifier. |
|
| 130 |
+
| `name` | Component name from `_chem_comp.name`. |
|
| 131 |
+
| `component_type` | Raw `_chem_comp.type` value. |
|
| 132 |
+
| `pdbx_type` | Raw `_chem_comp.pdbx_type` value. |
|
| 133 |
+
| `formula` | Chemical formula. |
|
| 134 |
+
| `formula_weight` | Formula weight as a float. |
|
| 135 |
+
| `formal_charge` | Formal charge as an integer. |
|
| 136 |
+
| `mon_nstd_parent_comp_id` | Parent component ID for non-standard monomers, when present. |
|
| 137 |
+
| `one_letter_code` | One-letter code, when present. |
|
| 138 |
+
| `three_letter_code` | Three-letter code, when present. |
|
| 139 |
+
| `pdbx_synonyms` | Synonym field from `_chem_comp`. |
|
| 140 |
+
| `synonym_names` | Synonyms from `pdbx_chem_comp_synonyms`. |
|
| 141 |
+
| `initial_date` | Initial component date. |
|
| 142 |
+
| `modified_date` | Last modified date. |
|
| 143 |
+
| `release_status` | Release status, such as `REL` or `OBS`. |
|
| 144 |
+
| `replaced_by` | Replacement component ID, when present. |
|
| 145 |
+
| `replaces` | Component ID replaced by this component, when present. |
|
| 146 |
+
| `atom_ids` | Atom identifiers from `chem_comp_atom`. |
|
| 147 |
+
| `atom_elements` | Element symbols for `atom_ids`. |
|
| 148 |
+
| `atom_charges` | Atom charges. |
|
| 149 |
+
| `atom_aromatic_flags` | Atom aromatic flags. |
|
| 150 |
+
| `atom_leaving_flags` | Atom leaving-atom flags. |
|
| 151 |
+
| `atom_stereo_configs` | Atom stereochemistry flags. |
|
| 152 |
+
| `atom_count` | Number of atoms. |
|
| 153 |
+
| `heavy_atom_count` | Number of non-hydrogen atoms. |
|
| 154 |
+
| `hydrogen_atom_count` | Number of hydrogen atoms. |
|
| 155 |
+
| `bond_atom_id_1` | First atom ID for each bond. |
|
| 156 |
+
| `bond_atom_id_2` | Second atom ID for each bond. |
|
| 157 |
+
| `bond_orders` | Bond order values. |
|
| 158 |
+
| `bond_aromatic_flags` | Bond aromatic flags. |
|
| 159 |
+
| `bond_stereo_configs` | Bond stereochemistry flags. |
|
| 160 |
+
| `bond_count` | Number of bonds. |
|
| 161 |
+
| `descriptor_types` | Descriptor types such as `SMILES`, `SMILES_CANONICAL`, `InChI`, and `InChIKey`. |
|
| 162 |
+
| `descriptors` | Descriptor values. |
|
| 163 |
+
| `canonical_smiles` | First `SMILES_CANONICAL` descriptor. |
|
| 164 |
+
| `smiles` | First `SMILES` descriptor. |
|
| 165 |
+
| `inchi` | First `InChI` descriptor. |
|
| 166 |
+
| `inchikey` | First `InChIKey` descriptor. |
|
| 167 |
+
| `identifier_types` | Identifier types from `pdbx_chem_comp_identifier`. |
|
| 168 |
+
| `identifiers` | Identifier values. |
|
| 169 |
+
| `systematic_names` | Identifier values whose type is `SYSTEMATIC NAME`. |
|
| 170 |
+
| `audit_actions` | Audit action types. |
|
| 171 |
+
| `audit_dates` | Audit dates. |
|
| 172 |
+
| `related_component_ids` | Related component IDs, when present. |
|
| 173 |
+
| `pcm_ids` | Protein modification annotation IDs, when present. |
|
| 174 |
+
| `pcm_modified_residue_ids` | Modified residue IDs from PCM annotations. |
|
| 175 |
+
| `feature_types` | Feature types from `pdbx_chem_comp_feature`. |
|
| 176 |
+
| `feature_values` | Feature values from `pdbx_chem_comp_feature`. |
|
| 177 |
+
| `split_bucket` | Deterministic split bucket from `sha256(component_id) % 10`. |
|
| 178 |
+
|
| 179 |
+
## Preparation
|
| 180 |
+
|
| 181 |
+
The normalization script used to create the Parquet files is included at `scripts/prepare_pdb_ccd_dataset.py`.
|
data/test-00000-of-00001.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cb1db955591cd95fa9cd7163521579d4dfc4c67340dd765f6b1b5c60b49ba4c2
|
| 3 |
+
size 3541545
|
data/train-00000-of-00001.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:bcae608a02fff04fa063ef18309f73df775fab0724736a251449103fb1f3869a
|
| 3 |
+
size 28722657
|
dataset_summary.json
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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iteFold/PDB-CCD",
|
| 3 |
+
"component_rows": 50054,
|
| 4 |
+
"splits": {
|
| 5 |
+
"train": 45045,
|
| 6 |
+
"test": 5009
|
| 7 |
+
},
|
| 8 |
+
"split_strategy": "deterministic sha256(component_id) % 10; bucket 0 is test, buckets 1-9 are train",
|
| 9 |
+
"release_status_counts": {
|
| 10 |
+
"REL": 49292,
|
| 11 |
+
"OBS": 762
|
| 12 |
+
},
|
| 13 |
+
"component_type_counts": {
|
| 14 |
+
"NON-POLYMER": 26117,
|
| 15 |
+
"non-polymer": 19493,
|
| 16 |
+
"L-PEPTIDE LINKING": 923,
|
| 17 |
+
"L-peptide linking": 580,
|
| 18 |
+
"peptide-like": 556,
|
| 19 |
+
"D-saccharide": 405,
|
| 20 |
+
"DNA LINKING": 325,
|
| 21 |
+
"RNA LINKING": 223,
|
| 22 |
+
"D-saccharide, alpha linking": 203,
|
| 23 |
+
"D-saccharide, beta linking": 173,
|
| 24 |
+
"saccharide": 137,
|
| 25 |
+
"DNA linking": 134,
|
| 26 |
+
"RNA linking": 129,
|
| 27 |
+
"D-PEPTIDE LINKING": 96,
|
| 28 |
+
"D-peptide linking": 68,
|
| 29 |
+
"L-saccharide, alpha linking": 63,
|
| 30 |
+
"peptide linking": 62,
|
| 31 |
+
"L-saccharide": 60,
|
| 32 |
+
"SACCHARIDE": 51,
|
| 33 |
+
"PEPTIDE-LIKE": 48,
|
| 34 |
+
"PEPTIDE LINKING": 44,
|
| 35 |
+
"D-SACCHARIDE": 43,
|
| 36 |
+
"L-saccharide, beta linking": 35,
|
| 37 |
+
"L-peptide NH3 amino terminus": 25,
|
| 38 |
+
"L-peptide COOH carboxy terminus": 13,
|
| 39 |
+
"L-SACCHARIDE": 8,
|
| 40 |
+
"RNA OH 3 prime terminus": 5,
|
| 41 |
+
"L-RNA LINKING": 5,
|
| 42 |
+
"L-DNA LINKING": 4,
|
| 43 |
+
"D-beta-peptide, C-gamma linking": 3,
|
| 44 |
+
"DNA OH 3 prime terminus": 3,
|
| 45 |
+
"L-beta-peptide, C-gamma linking": 3,
|
| 46 |
+
"RNA OH 5 prime terminus": 2,
|
| 47 |
+
"L-gamma-peptide, C-delta linking": 2,
|
| 48 |
+
"L-RNA linking": 2,
|
| 49 |
+
"L-PEPTIDE COOH CARBOXY TERMINUS": 2,
|
| 50 |
+
"DNA OH 5 prime terminus": 2,
|
| 51 |
+
"D-gamma-peptide, C-delta linking": 1,
|
| 52 |
+
"D-PEPTIDE NH3 AMINO TERMINUS": 1,
|
| 53 |
+
"Peptide-like": 1,
|
| 54 |
+
"L-DNA linking": 1,
|
| 55 |
+
"D-peptide COOH carboxy terminus": 1,
|
| 56 |
+
"DNA OH 3 PRIME TERMINUS": 1,
|
| 57 |
+
"D-peptide NH3 amino terminus": 1
|
| 58 |
+
},
|
| 59 |
+
"pdbx_type_counts": {
|
| 60 |
+
"HETAIN": 45506,
|
| 61 |
+
"ATOMP": 1831,
|
| 62 |
+
"ATOMS": 1182,
|
| 63 |
+
"ATOMN": 820,
|
| 64 |
+
"missing": 256,
|
| 65 |
+
"HETAD": 247,
|
| 66 |
+
"HETAI": 135,
|
| 67 |
+
"HETIC": 38,
|
| 68 |
+
"HETAC": 32,
|
| 69 |
+
"HETAS": 5,
|
| 70 |
+
"hetain": 2
|
| 71 |
+
},
|
| 72 |
+
"max_modified_date": "2026-04-24",
|
| 73 |
+
"components_with_atoms": 49947,
|
| 74 |
+
"components_with_bonds": 49921,
|
| 75 |
+
"components_with_descriptors": 50052,
|
| 76 |
+
"components_with_identifiers": 37058,
|
| 77 |
+
"components_with_pcm": 613,
|
| 78 |
+
"top_elements": {
|
| 79 |
+
"H": 1082721,
|
| 80 |
+
"C": 898683,
|
| 81 |
+
"O": 199913,
|
| 82 |
+
"N": 152744,
|
| 83 |
+
"F": 17030,
|
| 84 |
+
"S": 15656,
|
| 85 |
+
"CL": 8840,
|
| 86 |
+
"P": 7757,
|
| 87 |
+
"BR": 1827,
|
| 88 |
+
"B": 983,
|
| 89 |
+
"FE": 445,
|
| 90 |
+
"I": 427,
|
| 91 |
+
"W": 426,
|
| 92 |
+
"MO": 205,
|
| 93 |
+
"V": 195,
|
| 94 |
+
"RU": 156,
|
| 95 |
+
"SE": 154,
|
| 96 |
+
"CO": 78,
|
| 97 |
+
"SI": 63,
|
| 98 |
+
"CU": 63,
|
| 99 |
+
"PT": 58,
|
| 100 |
+
"MG": 41,
|
| 101 |
+
"NI": 40,
|
| 102 |
+
"RH": 38,
|
| 103 |
+
"MN": 36,
|
| 104 |
+
"AS": 32,
|
| 105 |
+
"IR": 28,
|
| 106 |
+
"D": 23,
|
| 107 |
+
"HG": 22,
|
| 108 |
+
"ZN": 20
|
| 109 |
+
},
|
| 110 |
+
"descriptor_type_counts": {
|
| 111 |
+
"SMILES": 134251,
|
| 112 |
+
"SMILES_CANONICAL": 100067,
|
| 113 |
+
"InChI": 50046,
|
| 114 |
+
"InChIKey": 50045,
|
| 115 |
+
"INCHI": 4
|
| 116 |
+
},
|
| 117 |
+
"identifier_type_counts": {
|
| 118 |
+
"SYSTEMATIC NAME": 70318,
|
| 119 |
+
"IUPAC CARBOHYDRATE SYMBOL": 301,
|
| 120 |
+
"CONDENSED IUPAC CARBOHYDRATE SYMBOL": 173,
|
| 121 |
+
"COMMON NAME": 169,
|
| 122 |
+
"SNFG CARBOHYDRATE SYMBOL": 122
|
| 123 |
+
},
|
| 124 |
+
"columns": [
|
| 125 |
+
"component_id",
|
| 126 |
+
"name",
|
| 127 |
+
"component_type",
|
| 128 |
+
"pdbx_type",
|
| 129 |
+
"formula",
|
| 130 |
+
"formula_weight",
|
| 131 |
+
"formal_charge",
|
| 132 |
+
"mon_nstd_parent_comp_id",
|
| 133 |
+
"one_letter_code",
|
| 134 |
+
"three_letter_code",
|
| 135 |
+
"pdbx_synonyms",
|
| 136 |
+
"synonym_names",
|
| 137 |
+
"synonym_provenances",
|
| 138 |
+
"synonym_types",
|
| 139 |
+
"initial_date",
|
| 140 |
+
"modified_date",
|
| 141 |
+
"release_status",
|
| 142 |
+
"ambiguous_flag",
|
| 143 |
+
"replaced_by",
|
| 144 |
+
"replaces",
|
| 145 |
+
"model_coordinates_missing_flag",
|
| 146 |
+
"ideal_coordinates_missing_flag",
|
| 147 |
+
"model_coordinates_db_code",
|
| 148 |
+
"processing_site",
|
| 149 |
+
"atom_ids",
|
| 150 |
+
"atom_alt_ids",
|
| 151 |
+
"atom_elements",
|
| 152 |
+
"atom_charges",
|
| 153 |
+
"atom_aromatic_flags",
|
| 154 |
+
"atom_leaving_flags",
|
| 155 |
+
"atom_stereo_configs",
|
| 156 |
+
"atom_count",
|
| 157 |
+
"heavy_atom_count",
|
| 158 |
+
"hydrogen_atom_count",
|
| 159 |
+
"bond_atom_id_1",
|
| 160 |
+
"bond_atom_id_2",
|
| 161 |
+
"bond_orders",
|
| 162 |
+
"bond_aromatic_flags",
|
| 163 |
+
"bond_stereo_configs",
|
| 164 |
+
"bond_count",
|
| 165 |
+
"descriptor_types",
|
| 166 |
+
"descriptor_programs",
|
| 167 |
+
"descriptor_program_versions",
|
| 168 |
+
"descriptors",
|
| 169 |
+
"canonical_smiles",
|
| 170 |
+
"smiles",
|
| 171 |
+
"inchi",
|
| 172 |
+
"inchikey",
|
| 173 |
+
"identifier_types",
|
| 174 |
+
"identifier_programs",
|
| 175 |
+
"identifier_program_versions",
|
| 176 |
+
"identifiers",
|
| 177 |
+
"systematic_names",
|
| 178 |
+
"audit_actions",
|
| 179 |
+
"audit_dates",
|
| 180 |
+
"audit_processing_sites",
|
| 181 |
+
"related_component_ids",
|
| 182 |
+
"related_relationship_types",
|
| 183 |
+
"pcm_ids",
|
| 184 |
+
"pcm_modified_residue_ids",
|
| 185 |
+
"pcm_types",
|
| 186 |
+
"pcm_categories",
|
| 187 |
+
"pcm_positions",
|
| 188 |
+
"feature_types",
|
| 189 |
+
"feature_values",
|
| 190 |
+
"split_bucket"
|
| 191 |
+
],
|
| 192 |
+
"source_files_used": [
|
| 193 |
+
"components.cif.gz"
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Build viewer-friendly Parquet splits for LiteFold/PDB-CCD."""
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import argparse
|
| 7 |
+
import gzip
|
| 8 |
+
import hashlib
|
| 9 |
+
import json
|
| 10 |
+
import re
|
| 11 |
+
import shutil
|
| 12 |
+
from collections import Counter
|
| 13 |
+
from dataclasses import dataclass
|
| 14 |
+
from pathlib import Path
|
| 15 |
+
from typing import Any, Iterator
|
| 16 |
+
|
| 17 |
+
import pandas as pd
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
COMPONENT_COLUMNS = [
|
| 21 |
+
"component_id",
|
| 22 |
+
"name",
|
| 23 |
+
"component_type",
|
| 24 |
+
"pdbx_type",
|
| 25 |
+
"formula",
|
| 26 |
+
"formula_weight",
|
| 27 |
+
"formal_charge",
|
| 28 |
+
"mon_nstd_parent_comp_id",
|
| 29 |
+
"one_letter_code",
|
| 30 |
+
"three_letter_code",
|
| 31 |
+
"pdbx_synonyms",
|
| 32 |
+
"synonym_names",
|
| 33 |
+
"synonym_provenances",
|
| 34 |
+
"synonym_types",
|
| 35 |
+
"initial_date",
|
| 36 |
+
"modified_date",
|
| 37 |
+
"release_status",
|
| 38 |
+
"ambiguous_flag",
|
| 39 |
+
"replaced_by",
|
| 40 |
+
"replaces",
|
| 41 |
+
"model_coordinates_missing_flag",
|
| 42 |
+
"ideal_coordinates_missing_flag",
|
| 43 |
+
"model_coordinates_db_code",
|
| 44 |
+
"processing_site",
|
| 45 |
+
"atom_ids",
|
| 46 |
+
"atom_alt_ids",
|
| 47 |
+
"atom_elements",
|
| 48 |
+
"atom_charges",
|
| 49 |
+
"atom_aromatic_flags",
|
| 50 |
+
"atom_leaving_flags",
|
| 51 |
+
"atom_stereo_configs",
|
| 52 |
+
"atom_count",
|
| 53 |
+
"heavy_atom_count",
|
| 54 |
+
"hydrogen_atom_count",
|
| 55 |
+
"bond_atom_id_1",
|
| 56 |
+
"bond_atom_id_2",
|
| 57 |
+
"bond_orders",
|
| 58 |
+
"bond_aromatic_flags",
|
| 59 |
+
"bond_stereo_configs",
|
| 60 |
+
"bond_count",
|
| 61 |
+
"descriptor_types",
|
| 62 |
+
"descriptor_programs",
|
| 63 |
+
"descriptor_program_versions",
|
| 64 |
+
"descriptors",
|
| 65 |
+
"canonical_smiles",
|
| 66 |
+
"smiles",
|
| 67 |
+
"inchi",
|
| 68 |
+
"inchikey",
|
| 69 |
+
"identifier_types",
|
| 70 |
+
"identifier_programs",
|
| 71 |
+
"identifier_program_versions",
|
| 72 |
+
"identifiers",
|
| 73 |
+
"systematic_names",
|
| 74 |
+
"audit_actions",
|
| 75 |
+
"audit_dates",
|
| 76 |
+
"audit_processing_sites",
|
| 77 |
+
"related_component_ids",
|
| 78 |
+
"related_relationship_types",
|
| 79 |
+
"pcm_ids",
|
| 80 |
+
"pcm_modified_residue_ids",
|
| 81 |
+
"pcm_types",
|
| 82 |
+
"pcm_categories",
|
| 83 |
+
"pcm_positions",
|
| 84 |
+
"feature_types",
|
| 85 |
+
"feature_values",
|
| 86 |
+
"split_bucket",
|
| 87 |
+
]
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
@dataclass
|
| 91 |
+
class TokenStream:
|
| 92 |
+
iterator: Iterator[str]
|
| 93 |
+
pushed: list[str]
|
| 94 |
+
|
| 95 |
+
def next(self) -> str | None:
|
| 96 |
+
if self.pushed:
|
| 97 |
+
return self.pushed.pop()
|
| 98 |
+
return next(self.iterator, None)
|
| 99 |
+
|
| 100 |
+
def push(self, token: str) -> None:
|
| 101 |
+
self.pushed.append(token)
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def cif_tokens(path: Path) -> Iterator[str]:
|
| 105 |
+
with gzip.open(path, "rt", encoding="utf-8", errors="replace") as handle:
|
| 106 |
+
multiline: list[str] | None = None
|
| 107 |
+
for raw_line in handle:
|
| 108 |
+
line = raw_line.rstrip("\n")
|
| 109 |
+
if multiline is not None:
|
| 110 |
+
if line.startswith(";"):
|
| 111 |
+
yield "\n".join(multiline).strip()
|
| 112 |
+
multiline = None
|
| 113 |
+
else:
|
| 114 |
+
multiline.append(line)
|
| 115 |
+
continue
|
| 116 |
+
if line.startswith(";"):
|
| 117 |
+
multiline = [line[1:]]
|
| 118 |
+
continue
|
| 119 |
+
|
| 120 |
+
i = 0
|
| 121 |
+
length = len(line)
|
| 122 |
+
while i < length:
|
| 123 |
+
while i < length and line[i].isspace():
|
| 124 |
+
i += 1
|
| 125 |
+
if i >= length:
|
| 126 |
+
break
|
| 127 |
+
if line[i] == "#":
|
| 128 |
+
break
|
| 129 |
+
if line[i] in {"'", '"'}:
|
| 130 |
+
quote = line[i]
|
| 131 |
+
i += 1
|
| 132 |
+
value: list[str] = []
|
| 133 |
+
while i < length:
|
| 134 |
+
char = line[i]
|
| 135 |
+
if char == quote:
|
| 136 |
+
next_index = i + 1
|
| 137 |
+
if next_index >= length or line[next_index].isspace() or line[next_index] == "#":
|
| 138 |
+
i += 1
|
| 139 |
+
break
|
| 140 |
+
value.append(char)
|
| 141 |
+
i += 1
|
| 142 |
+
yield "".join(value)
|
| 143 |
+
continue
|
| 144 |
+
|
| 145 |
+
start = i
|
| 146 |
+
while i < length and not line[i].isspace() and line[i] != "#":
|
| 147 |
+
i += 1
|
| 148 |
+
yield line[start:i]
|
| 149 |
+
if i < length and line[i] == "#":
|
| 150 |
+
break
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
def clean_value(value: str | None) -> Any:
|
| 154 |
+
if value in {None, "?", "."}:
|
| 155 |
+
return None
|
| 156 |
+
return re.sub(r"\s+", " ", value).strip()
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
def parse_int(value: Any) -> int | None:
|
| 160 |
+
value = clean_value(value)
|
| 161 |
+
if value is None:
|
| 162 |
+
return None
|
| 163 |
+
try:
|
| 164 |
+
return int(value)
|
| 165 |
+
except (TypeError, ValueError):
|
| 166 |
+
return None
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
def parse_float(value: Any) -> float | None:
|
| 170 |
+
value = clean_value(value)
|
| 171 |
+
if value is None:
|
| 172 |
+
return None
|
| 173 |
+
try:
|
| 174 |
+
return float(value)
|
| 175 |
+
except (TypeError, ValueError):
|
| 176 |
+
return None
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
def stable_bucket(value: str, buckets: int = 10) -> int:
|
| 180 |
+
digest = hashlib.sha256(value.encode("utf-8")).hexdigest()[:16]
|
| 181 |
+
return int(digest, 16) % buckets
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
def split_tag(tag: str) -> tuple[str, str]:
|
| 185 |
+
body = tag[1:]
|
| 186 |
+
category, field = body.split(".", 1)
|
| 187 |
+
return category, field
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
def finish_loop(tags: list[str], values: list[str], loops: dict[str, list[dict[str, Any]]]) -> None:
|
| 191 |
+
if not tags:
|
| 192 |
+
return
|
| 193 |
+
categories = {split_tag(tag)[0] for tag in tags}
|
| 194 |
+
if len(categories) != 1:
|
| 195 |
+
return
|
| 196 |
+
category = categories.pop()
|
| 197 |
+
fields = [split_tag(tag)[1] for tag in tags]
|
| 198 |
+
width = len(fields)
|
| 199 |
+
rows = []
|
| 200 |
+
for start in range(0, len(values) - (len(values) % width), width):
|
| 201 |
+
rows.append({field: clean_value(values[start + index]) for index, field in enumerate(fields)})
|
| 202 |
+
loops.setdefault(category, []).extend(rows)
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
def parse_cif_blocks(path: Path) -> Iterator[dict[str, Any]]:
|
| 206 |
+
stream = TokenStream(cif_tokens(path), [])
|
| 207 |
+
block: dict[str, Any] | None = None
|
| 208 |
+
|
| 209 |
+
while True:
|
| 210 |
+
token = stream.next()
|
| 211 |
+
if token is None:
|
| 212 |
+
if block is not None:
|
| 213 |
+
yield block
|
| 214 |
+
break
|
| 215 |
+
|
| 216 |
+
if token.startswith("data_"):
|
| 217 |
+
if block is not None:
|
| 218 |
+
yield block
|
| 219 |
+
block = {"name": token[5:], "scalars": {}, "loops": {}}
|
| 220 |
+
continue
|
| 221 |
+
|
| 222 |
+
if block is None:
|
| 223 |
+
continue
|
| 224 |
+
|
| 225 |
+
if token == "loop_":
|
| 226 |
+
tags: list[str] = []
|
| 227 |
+
values: list[str] = []
|
| 228 |
+
while True:
|
| 229 |
+
item = stream.next()
|
| 230 |
+
if item is None:
|
| 231 |
+
break
|
| 232 |
+
if item.startswith("_"):
|
| 233 |
+
tags.append(item)
|
| 234 |
+
continue
|
| 235 |
+
stream.push(item)
|
| 236 |
+
break
|
| 237 |
+
while True:
|
| 238 |
+
item = stream.next()
|
| 239 |
+
if item is None:
|
| 240 |
+
finish_loop(tags, values, block["loops"])
|
| 241 |
+
return
|
| 242 |
+
if item == "loop_" or item.startswith("data_") or item.startswith("_"):
|
| 243 |
+
stream.push(item)
|
| 244 |
+
break
|
| 245 |
+
values.append(item)
|
| 246 |
+
finish_loop(tags, values, block["loops"])
|
| 247 |
+
continue
|
| 248 |
+
|
| 249 |
+
if token.startswith("_"):
|
| 250 |
+
value = stream.next()
|
| 251 |
+
if value is None:
|
| 252 |
+
continue
|
| 253 |
+
if value == "loop_" or value.startswith("data_") or value.startswith("_"):
|
| 254 |
+
stream.push(value)
|
| 255 |
+
continue
|
| 256 |
+
category, field = split_tag(token)
|
| 257 |
+
block["scalars"].setdefault(category, {})[field] = clean_value(value)
|
| 258 |
+
|
| 259 |
+
|
| 260 |
+
def first_by_type(rows: list[dict[str, Any]], wanted_type: str) -> str | None:
|
| 261 |
+
for row in rows:
|
| 262 |
+
if row.get("type") == wanted_type and row.get("descriptor"):
|
| 263 |
+
return str(row["descriptor"])
|
| 264 |
+
return None
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
def values(rows: list[dict[str, Any]], field: str) -> list[Any]:
|
| 268 |
+
return [row[field] for row in rows if row.get(field) is not None]
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
def string_values(rows: list[dict[str, Any]], field: str) -> list[str]:
|
| 272 |
+
return [str(row[field]) for row in rows if row.get(field) is not None]
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
def int_values(rows: list[dict[str, Any]], field: str) -> list[int]:
|
| 276 |
+
parsed = []
|
| 277 |
+
for row in rows:
|
| 278 |
+
value = parse_int(row.get(field))
|
| 279 |
+
if value is not None:
|
| 280 |
+
parsed.append(value)
|
| 281 |
+
return parsed
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
def component_row(block: dict[str, Any]) -> dict[str, Any]:
|
| 285 |
+
scalars = block["scalars"].get("chem_comp", {})
|
| 286 |
+
loops = block["loops"]
|
| 287 |
+
atoms = loops.get("chem_comp_atom", [])
|
| 288 |
+
bonds = loops.get("chem_comp_bond", [])
|
| 289 |
+
descriptors = loops.get("pdbx_chem_comp_descriptor", [])
|
| 290 |
+
identifiers = loops.get("pdbx_chem_comp_identifier", [])
|
| 291 |
+
audits = loops.get("pdbx_chem_comp_audit", [])
|
| 292 |
+
synonyms = loops.get("pdbx_chem_comp_synonyms", [])
|
| 293 |
+
related = loops.get("pdbx_chem_comp_related", [])
|
| 294 |
+
pcms = loops.get("pdbx_chem_comp_pcm", [])
|
| 295 |
+
features = loops.get("pdbx_chem_comp_feature", [])
|
| 296 |
+
|
| 297 |
+
component_id = str(scalars.get("id") or block["name"])
|
| 298 |
+
atom_elements = string_values(atoms, "type_symbol")
|
| 299 |
+
heavy_atom_count = sum(1 for element in atom_elements if element.upper() != "H")
|
| 300 |
+
hydrogen_atom_count = sum(1 for element in atom_elements if element.upper() == "H")
|
| 301 |
+
|
| 302 |
+
return {
|
| 303 |
+
"component_id": component_id,
|
| 304 |
+
"name": scalars.get("name"),
|
| 305 |
+
"component_type": scalars.get("type"),
|
| 306 |
+
"pdbx_type": scalars.get("pdbx_type"),
|
| 307 |
+
"formula": scalars.get("formula"),
|
| 308 |
+
"formula_weight": parse_float(scalars.get("formula_weight")),
|
| 309 |
+
"formal_charge": parse_int(scalars.get("pdbx_formal_charge")),
|
| 310 |
+
"mon_nstd_parent_comp_id": scalars.get("mon_nstd_parent_comp_id"),
|
| 311 |
+
"one_letter_code": scalars.get("one_letter_code"),
|
| 312 |
+
"three_letter_code": scalars.get("three_letter_code"),
|
| 313 |
+
"pdbx_synonyms": scalars.get("pdbx_synonyms"),
|
| 314 |
+
"synonym_names": string_values(synonyms, "name"),
|
| 315 |
+
"synonym_provenances": string_values(synonyms, "provenance"),
|
| 316 |
+
"synonym_types": string_values(synonyms, "type"),
|
| 317 |
+
"initial_date": scalars.get("pdbx_initial_date"),
|
| 318 |
+
"modified_date": scalars.get("pdbx_modified_date"),
|
| 319 |
+
"release_status": scalars.get("pdbx_release_status"),
|
| 320 |
+
"ambiguous_flag": scalars.get("pdbx_ambiguous_flag"),
|
| 321 |
+
"replaced_by": scalars.get("pdbx_replaced_by"),
|
| 322 |
+
"replaces": scalars.get("pdbx_replaces"),
|
| 323 |
+
"model_coordinates_missing_flag": scalars.get("pdbx_model_coordinates_missing_flag"),
|
| 324 |
+
"ideal_coordinates_missing_flag": scalars.get("pdbx_ideal_coordinates_missing_flag"),
|
| 325 |
+
"model_coordinates_db_code": scalars.get("pdbx_model_coordinates_db_code"),
|
| 326 |
+
"processing_site": scalars.get("pdbx_processing_site"),
|
| 327 |
+
"atom_ids": string_values(atoms, "atom_id"),
|
| 328 |
+
"atom_alt_ids": string_values(atoms, "alt_atom_id"),
|
| 329 |
+
"atom_elements": atom_elements,
|
| 330 |
+
"atom_charges": int_values(atoms, "charge"),
|
| 331 |
+
"atom_aromatic_flags": string_values(atoms, "pdbx_aromatic_flag"),
|
| 332 |
+
"atom_leaving_flags": string_values(atoms, "pdbx_leaving_atom_flag"),
|
| 333 |
+
"atom_stereo_configs": string_values(atoms, "pdbx_stereo_config"),
|
| 334 |
+
"atom_count": len(atoms),
|
| 335 |
+
"heavy_atom_count": heavy_atom_count,
|
| 336 |
+
"hydrogen_atom_count": hydrogen_atom_count,
|
| 337 |
+
"bond_atom_id_1": string_values(bonds, "atom_id_1"),
|
| 338 |
+
"bond_atom_id_2": string_values(bonds, "atom_id_2"),
|
| 339 |
+
"bond_orders": string_values(bonds, "value_order"),
|
| 340 |
+
"bond_aromatic_flags": string_values(bonds, "pdbx_aromatic_flag"),
|
| 341 |
+
"bond_stereo_configs": string_values(bonds, "pdbx_stereo_config"),
|
| 342 |
+
"bond_count": len(bonds),
|
| 343 |
+
"descriptor_types": string_values(descriptors, "type"),
|
| 344 |
+
"descriptor_programs": string_values(descriptors, "program"),
|
| 345 |
+
"descriptor_program_versions": string_values(descriptors, "program_version"),
|
| 346 |
+
"descriptors": string_values(descriptors, "descriptor"),
|
| 347 |
+
"canonical_smiles": first_by_type(descriptors, "SMILES_CANONICAL"),
|
| 348 |
+
"smiles": first_by_type(descriptors, "SMILES"),
|
| 349 |
+
"inchi": first_by_type(descriptors, "InChI"),
|
| 350 |
+
"inchikey": first_by_type(descriptors, "InChIKey"),
|
| 351 |
+
"identifier_types": string_values(identifiers, "type"),
|
| 352 |
+
"identifier_programs": string_values(identifiers, "program"),
|
| 353 |
+
"identifier_program_versions": string_values(identifiers, "program_version"),
|
| 354 |
+
"identifiers": string_values(identifiers, "identifier"),
|
| 355 |
+
"systematic_names": [
|
| 356 |
+
str(row["identifier"])
|
| 357 |
+
for row in identifiers
|
| 358 |
+
if row.get("type") == "SYSTEMATIC NAME" and row.get("identifier") is not None
|
| 359 |
+
],
|
| 360 |
+
"audit_actions": string_values(audits, "action_type"),
|
| 361 |
+
"audit_dates": string_values(audits, "date"),
|
| 362 |
+
"audit_processing_sites": string_values(audits, "processing_site"),
|
| 363 |
+
"related_component_ids": string_values(related, "related_comp_id"),
|
| 364 |
+
"related_relationship_types": string_values(related, "relationship_type"),
|
| 365 |
+
"pcm_ids": string_values(pcms, "pcm_id"),
|
| 366 |
+
"pcm_modified_residue_ids": string_values(pcms, "modified_residue_id"),
|
| 367 |
+
"pcm_types": string_values(pcms, "type"),
|
| 368 |
+
"pcm_categories": string_values(pcms, "category"),
|
| 369 |
+
"pcm_positions": string_values(pcms, "position"),
|
| 370 |
+
"feature_types": string_values(features, "type"),
|
| 371 |
+
"feature_values": string_values(features, "value"),
|
| 372 |
+
"split_bucket": stable_bucket(component_id),
|
| 373 |
+
}
|
| 374 |
+
|
| 375 |
+
|
| 376 |
+
def build_dataset(raw_dir: Path, out_dir: Path) -> dict[str, Any]:
|
| 377 |
+
cif_path = raw_dir / "components.cif.gz"
|
| 378 |
+
rows = [component_row(block) for block in parse_cif_blocks(cif_path)]
|
| 379 |
+
|
| 380 |
+
if out_dir.exists():
|
| 381 |
+
shutil.rmtree(out_dir)
|
| 382 |
+
data_dir = out_dir / "data"
|
| 383 |
+
data_dir.mkdir(parents=True, exist_ok=True)
|
| 384 |
+
|
| 385 |
+
df = pd.DataFrame.from_records(rows, columns=COMPONENT_COLUMNS)
|
| 386 |
+
df = df.sort_values(["split_bucket", "component_id"], kind="mergesort")
|
| 387 |
+
train = df[df["split_bucket"].ne(0)].sort_values("component_id", kind="mergesort")
|
| 388 |
+
test = df[df["split_bucket"].eq(0)].sort_values("component_id", kind="mergesort")
|
| 389 |
+
train.to_parquet(data_dir / "train-00000-of-00001.parquet", index=False, compression="zstd")
|
| 390 |
+
test.to_parquet(data_dir / "test-00000-of-00001.parquet", index=False, compression="zstd")
|
| 391 |
+
|
| 392 |
+
def count_column(column: str) -> dict[str, int]:
|
| 393 |
+
return {
|
| 394 |
+
str(key): int(value)
|
| 395 |
+
for key, value in df[column].fillna("missing").value_counts(dropna=False).to_dict().items()
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
release_status_counts = count_column("release_status")
|
| 399 |
+
type_counts = count_column("component_type")
|
| 400 |
+
pdbx_type_counts = count_column("pdbx_type")
|
| 401 |
+
element_counts = Counter(element for elements in df["atom_elements"] for element in elements)
|
| 402 |
+
descriptor_type_counts = Counter(kind for kinds in df["descriptor_types"] for kind in kinds)
|
| 403 |
+
identifier_type_counts = Counter(kind for kinds in df["identifier_types"] for kind in kinds)
|
| 404 |
+
max_modified_date = max((value for value in df["modified_date"].dropna().tolist()), default=None)
|
| 405 |
+
|
| 406 |
+
summary = {
|
| 407 |
+
"source": "LiteFold/PDB-CCD",
|
| 408 |
+
"component_rows": int(len(df)),
|
| 409 |
+
"splits": {
|
| 410 |
+
"train": int(len(train)),
|
| 411 |
+
"test": int(len(test)),
|
| 412 |
+
},
|
| 413 |
+
"split_strategy": "deterministic sha256(component_id) % 10; bucket 0 is test, buckets 1-9 are train",
|
| 414 |
+
"release_status_counts": release_status_counts,
|
| 415 |
+
"component_type_counts": type_counts,
|
| 416 |
+
"pdbx_type_counts": pdbx_type_counts,
|
| 417 |
+
"max_modified_date": max_modified_date,
|
| 418 |
+
"components_with_atoms": int(df["atom_count"].gt(0).sum()),
|
| 419 |
+
"components_with_bonds": int(df["bond_count"].gt(0).sum()),
|
| 420 |
+
"components_with_descriptors": int(df["descriptors"].map(len).gt(0).sum()),
|
| 421 |
+
"components_with_identifiers": int(df["identifiers"].map(len).gt(0).sum()),
|
| 422 |
+
"components_with_pcm": int(df["pcm_ids"].map(len).gt(0).sum()),
|
| 423 |
+
"top_elements": dict(element_counts.most_common(30)),
|
| 424 |
+
"descriptor_type_counts": dict(descriptor_type_counts.most_common()),
|
| 425 |
+
"identifier_type_counts": dict(identifier_type_counts.most_common()),
|
| 426 |
+
"columns": COMPONENT_COLUMNS,
|
| 427 |
+
"source_files_used": ["components.cif.gz"],
|
| 428 |
+
}
|
| 429 |
+
(out_dir / "dataset_summary.json").write_text(json.dumps(summary, indent=2) + "\n", encoding="utf-8")
|
| 430 |
+
return summary
|
| 431 |
+
|
| 432 |
+
|
| 433 |
+
def main() -> None:
|
| 434 |
+
parser = argparse.ArgumentParser()
|
| 435 |
+
parser.add_argument("--raw-dir", type=Path, default=Path("LiteFold_PDB_CCD_raw"))
|
| 436 |
+
parser.add_argument("--out-dir", type=Path, default=Path("LiteFold_PDB_CCD_processed"))
|
| 437 |
+
args = parser.parse_args()
|
| 438 |
+
summary = build_dataset(args.raw_dir, args.out_dir)
|
| 439 |
+
print(json.dumps(summary, indent=2))
|
| 440 |
+
|
| 441 |
+
|
| 442 |
+
if __name__ == "__main__":
|
| 443 |
+
main()
|