project-gemmi / gemmi

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

[FEATURE REQUEST] set types to type_energy in chem comp output #270

Closed rimmartin closed 1 year ago

rimmartin commented 1 year ago

A way to pass in or get types to the type_energy column.

Example:

data_comp_CLR
#
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
CLR         C1     C   CH2   .          6.9767   12.4450    3.1228
CLR         C2     C   CH2   .          6.8443   13.7108    2.2706
CLR         C3     C   CH1   .          5.4245   13.9817    1.8902
CLR         C4     C   CH2   .          4.7516   12.6775    1.4925
CLR         C5     C   C     .          4.5842   12.0895    2.9509
CLR         C6     C   C1    .          3.5087   11.4065    3.2582
CLR         C7     C   CH2   .          3.6300    9.9956    3.7145
...

The make_chemcomp_with_restraints sets the chem_type from the Element uname which currently is an all caps of the element symbol?

Determining the types seems to involve perception and topology outside the purvey of gemmi. Would it fit gemmi to provide a way to externally set these types?

wojdyr commented 1 year ago

You can change type_energy (or anything else) using generic functions for working with CIF blocks. For example:

// gemmi::add_chemcomp_to_block(..., new_block);
for (auto row : new_block.find("_chem_comp_atom.", {"atom_id", "type_energy"}))
  row[1] = row[0] + "_1";  // type_energy = atom_id + "_1"
// gemmi::cif::write_cif_block_to_stream(...);