project-gemmi / gemmi

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

Creating a structure from list of residues and their coordinates #315

Closed marinegor closed 1 month ago

marinegor commented 1 month ago

Hi everyone, sorry to bother you again -- I wonder how I could actually write an mmcif file, given e.g. a list of atom names + residue names + coordinates?

I'm searching for an interface like:

import gemmi
import numpy as np

my_object = ...
np_structure: np.ndarray = np.array([(atomname, resname, *coords) for atomname, resname, coords in my_object])
gemmi_structure = gemmi.Structure.from_numpy(np_structure)  # this is the method that I'm struggling to find
gemmi_structure.write_mmcif(...)  # and this as well

could you point me to the right direction please?

wojdyr commented 1 month ago

mmCIF files tend to have more information, although in principle write only a subset of it. I suppose in this case the occupancy is 1.0 and there are no alternative conformations, and you want a single chain. But you still need to assign the chain name, B-factors and sequence IDs (other programs will expect it). Sequence IDs can't be determined from the resname alone, because consecutive residues can have the same resname. The elements, if you want to have them in a file, would need to be looked up in CCD.

There is no similar function. It's only possible to do it by constructing all the objects (chains,residues,atoms) one by one. Or by constructing directly a CIF Document using functions such as set_mmcif_category.

marinegor commented 1 month ago

There is no similar function. It's only possible to do it by constructing all the objects (chains,residues,atoms) one by one.

Oh, I see, thanks! I guess I should also initialize all sub-attributes by hand, e.g. gemmi.Position, gemmi.Element, etc.