You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{py:func}`~moleculekit.tools.preparation.systemPrepare` calls {py:func}`~moleculekit.tools.nonstandard_residues.detectNonStandardResidues` internally, so it will pick
202
202
up the ligand spec automatically.
203
203
204
+
If you already have the residue as a reference structure with correct
205
+
connectivity (e.g. an RCSB chemical-component CIF), use
206
+
{py:meth}`~moleculekit.molecule.Molecule.templateResidueFromMolecule` instead of
207
+
a SMILES string. It matches the residue to the reference by atom name (the two
208
+
must share the same heavy-atom names) and copies the reference's bond orders and
209
+
formal charges verbatim, so those must already be correct in the reference:
210
+
211
+
```python
212
+
ref = Molecule("LIG.cif") # correct bonds, bond orders, and formal charges
- Conversion needs explicit bonds. If `mol.bonds` is empty (plain PDB load), run {py:meth}`~moleculekit.molecule.Molecule.templateResidueFromSmiles` for non-canonical residues so the conversion gets correct bond orders, or pass `guessBonds=True` for a distance-based fallback.
98
+
- Conversion needs explicit bonds. If `mol.bonds` is empty (plain PDB load), run {py:meth}`~moleculekit.molecule.Molecule.templateResidueFromSmiles`(or {py:meth}`~moleculekit.molecule.Molecule.templateResidueFromMolecule`, when you have a reference structure such as a CIF with correct bond orders and formal charges) for non-canonical residues so the conversion gets correct bond orders, or pass `guessBonds=True` for a distance-based fallback.
99
99
-`sanitize=True` will raise on residues whose bonding or formal charges are inconsistent with chemical rules. For a freshly read PDB this often happens around metal centers and covalent ligands; template those residues first (see [Custom residues from SMILES](../tutorials/system-prep/03-custom-residues-from-smiles.md)).
100
100
- Hydrogens must be present for stereochemistry / valence checks. Run {py:func}`~moleculekit.tools.preparation.systemPrepare` (or set explicit Hs via `templateResidueFromSmiles(..., addHs=True)`) before conversion.
101
101
-`toOpenFFMolecule` requires `openff-toolkit` and `openff-units` installed.
Copy file name to clipboardExpand all lines: doc/source/how-to/guess-bonds.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,7 @@ assert mol.bonds.shape[0] > 0, "No bonds guessed — check coordinates and eleme
29
29
30
30
## Gotchas
31
31
32
-
-`mol.guessBonds()` does not infer bond orders; every entry in `mol.bondtype` is `"un"` (unknown). When bond orders matter (e.g. for {py:meth}`~moleculekit.molecule.Molecule.toRDKitMol` conversion or SMILES output), template the relevant residues from SMILES with {py:meth}`~moleculekit.molecule.Molecule.templateResidueFromSmiles` instead.
32
+
-`mol.guessBonds()` does not infer bond orders; every entry in `mol.bondtype` is `"un"` (unknown). When bond orders matter (e.g. for {py:meth}`~moleculekit.molecule.Molecule.toRDKitMol` conversion or SMILES output), template the relevant residues from SMILES with {py:meth}`~moleculekit.molecule.Molecule.templateResidueFromSmiles` instead, or from a reference {py:class}`~moleculekit.molecule.Molecule` (e.g. a CIF carrying correct bond orders and formal charges) with {py:meth}`~moleculekit.molecule.Molecule.templateResidueFromMolecule`.
33
33
- Very close non-bonded atoms (e.g. crystal contacts, stacking interactions) can be incorrectly identified as bonded.
34
34
-**Do not assign `mol.bonds = guess_bonds(mol)` directly.** Always use `mol.guessBonds()`, which updates `mol.bonds` and `mol.bondtype` together. See [The Molecule data model: Bonds](../explanation/molecule-data-model.md#bonds-bonds-and-bondtype) for why the two arrays must stay in lockstep.
- [System prep: custom residues from SMILES](tutorials/system-prep/03-custom-residues-from-smiles.md): `templateResidueFromSmiles` with `addHs=True`.
11
+
- [System prep: custom residues from SMILES](tutorials/system-prep/03-custom-residues-from-smiles.md): `templateResidueFromSmiles` with `addHs=True`; `templateResidueFromMolecule` to template from a reference Molecule (e.g. a CIF) carrying correct bond orders and formal charges.
12
12
- [System prep: mutation, gap closing, segmentation](tutorials/system-prep/04-mutation-gap-closing-segmentation.md): `mutateResidue`, `model_gaps`, `autoSegment`.
The per-resname atom counts after templating — each NCAA now carries heavy atoms + the hydrogens the SMILES specified.
98
98
99
+
### Alternative: template from a reference Molecule
100
+
101
+
If you already have the residue as a small reference structure that carries correct connectivity (for example an RCSB chemical-component CIF for the ligand), you can template from that {py:class}`~moleculekit.molecule.Molecule` instead of writing a SMILES string, using {py:meth}`~moleculekit.molecule.Molecule.templateResidueFromMolecule`:
102
+
103
+
```python
104
+
ref = Molecule("HRG.cif") # reference carrying correct bonds, bond orders, and formal charges
The reference is matched to the residue by **atom name** (not by MCS, as with SMILES), so the two must share the same set of heavy-atom names and the reference's heavy-atom names must be unique. The bond orders and formal charges are copied straight from the reference: they must therefore already be correct in the template Molecule, because `templateResidueFromMolecule` transfers them verbatim and does not re-derive them. Everything else (`addHs`, `guessBonds`, automatic cross-residue bond handling, and per-copy templating) works exactly as in the SMILES variant.
109
+
99
110
## Step 4 — Run systemPrepare
100
111
101
112
```{code-cell} python
@@ -116,6 +127,7 @@ The five NCAAs all survive the preparation pipeline with their full heavy-atom t
116
127
- It removes any hydrogens already on the matched residue and re-adds them from the SMILES (`addHs=True`), so the hydrogen pattern is deterministic — no manual pre-stripping needed.
117
128
- One SMILES per residue type; the templater handles every copy automatically and trims terminal atoms (OXT, terminal NH) for mid-chain residues.
118
129
- Cross-residue covalent bonds — peptide bonds, glycosidic bonds, isopeptide bonds — are detected automatically; the boundary atom's H count is corrected so it is not over-protonated.
130
+
- {py:meth}`~moleculekit.molecule.Molecule.templateResidueFromMolecule` is the same operation with a reference {py:class}`~moleculekit.molecule.Molecule` (e.g. a CIF) as the template instead of a SMILES string. It matches by atom name rather than MCS and copies the reference's bond orders and formal charges verbatim, so those must already be correct in the reference.
0 commit comments