project-gemmi / gemmi

macromolecular crystallography library and utilities
https://project-gemmi.github.io/
Mozilla Public License 2.0
220 stars 44 forks source link

[FEATURE REQUEST] put x, y, z columns in chemcomp _chem_comp_atom loop #267

Closed rimmartin closed 1 year ago

rimmartin commented 1 year ago

Hi,

In the _chem_comp_atom loop the add_chemcomp_to_block(add_chemcomp_to_block) the addition of x, y, z columns would be appreciated by my users to help them visualize the component. PyMol would open such a chem comp cif.

Example:

#
data_comp_4CK
#
loop_
_chem_comp_atom.comp_id
_chem_comp_atom.atom_id
_chem_comp_atom.type_symbol
_chem_comp_atom.type_energy
_chem_comp_atom.partial_charge
_chem_comp_atom.x
_chem_comp_atom.y
_chem_comp_atom.z
4CK N1  N   NR15    0.2996  0.7420  -3.6060 -28.9810    
4CK HN1 H   HNR5    0.27    0.5178  -2.6292 -29.1060    
4CK N2  N   NRD5    -0.7068 1.7410  -4.1850 -29.4630    
...
wojdyr commented 1 year ago

First, we'd have to store the coordinates somewhere. Currently, they are not in ChemComp::Atom. How do you store them in your program? There is also a question of how to name these columns. _chem_comp_atom.x is used in, for example, Refmac monomer library. In CCD and in PDBx/mmCIF spec x coordinates are named: _chem_comp_atom.model_Cartn_x and _chem_comp_atom.pdbx_model_Cartn_x_ideal.

rimmartin commented 1 year ago

I build a gemmi::Structure from our internal backbone and use

std::unique_ptr<gemmi::ChemComp>&& cc = gemmi::make_chemcomp_with_restraints((*it_residues));

to begin populating a gemmi::ChemComp for the atoms, bonds and angles. *it_residues is a gemmi::Residue. Then use internal properties to fill torsion, planar and chiral data structures into the same ChemComp. And they write out to stream

    gemmi::cif::Block new_block((*it_residues).name);
    gemmi::add_chemcomp_to_block(*cc.get(), new_block);
    gemmi::cif::write_cif_block_to_stream(buf, new_block, gemmi::cif::Style::Simple);

Would it fit other people's needs and gemmi design if the make_chemcomp_with_restraints moved a copy of the residue's coordinates to new properties for them in ChemComp::Atom?

I tested _chem_comp_atom.x, _chem_comp_atom.model_Cartn_x and _chem_comp_atom.pdbx_model_Cartn_x_ideal labels in cifs which are successfully read by pymol and moe

wojdyr commented 1 year ago

It makes sense. I'll add copying coordinates in make_chemcomp_with_restraints and add_chemcomp_to_block. This or next week.

rimmartin commented 1 year ago

Oh that will be fine! I got plenty of other things to do so a few weeks is good timing. Thank you

wojdyr commented 1 year ago

I added it. The coordinates can now be written as .x/y/z. If anyone would prefer to write it as model_Cartn_x/y/z in the future, I can add an option for it.