Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions src/chilife/MolSys.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,9 +569,14 @@ def write_cif(self, filename, use_bio_ccd: bool = True):
else:
local_ccd[res.resname] = res_to_ccd(res)

# Keep the per-residue CCD view for polymer-link detection in struct_conn emission before
# join_ccd_info flattens it into the CIF table form.
per_res_ccd = local_ccd
ccd_list = sorted(local_ccd.keys())
local_ccd = chilife.io.join_ccd_info(ccd_list, local_ccd)

struct_conn_data = chilife.io.struct_conn_from_bonds(self, ccd_data=per_res_ccd)

cif_data = {
self.name: {
"entry": {"id": self.name},
Expand Down Expand Up @@ -659,6 +664,9 @@ def write_cif(self, filename, use_bio_ccd: bool = True):
}
}

if struct_conn_data is not None:
cif_data[self.name]["struct_conn"] = struct_conn_data

# Delete empty entries
del_list = []
for k1, v1 in cif_data[self.name].items():
Expand Down Expand Up @@ -929,6 +937,14 @@ def __init__(
self.elements = self.atypes
self.bfactors = self.bs

# Map to atom index by chain, residue, insertion code, atom name, and altloc code.
self.crina = {
(str(c), str(r), str(i), str(n), str(a)): ii
for ii, (c, r, i, n, a) in enumerate(
zip(self.chains, self.resnums, self.icodes, self.names, self.altLocs)
)
}

self._bonds = None
self._bond_types = None
self._bond_mask = np.array([], dtype=bool)
Expand Down Expand Up @@ -1135,6 +1151,14 @@ def from_cif(cls, file_name):
name=name,
use_ccd=ccd_data,
)

# Parse inter-residue bonds from the _struct_conn loop (covale, disulf, metalc).
struct_conn = cif_data.get("struct_conn")
if struct_conn is not None:
sc_bonds, sc_types = chilife.io.parse_struct_conn_bonds(msys, struct_conn)
if len(sc_bonds) > 0:
msys.add_bonds(sc_bonds, bond_type=sc_types)

msys._cif_data = cif_data

return msys
Expand Down Expand Up @@ -2627,6 +2651,11 @@ def struct_to_cif_atom_site(struct):
).tolist()
occupancy = np.tile(struct.occupancies.astype(str), n_frames).tolist()
B_iso_or_equiv = np.tile(struct.bs.astype(str), n_frames).tolist()
formal_charge = np.tile(
[f"{charge:.0f}" if not np.isnan(charge) else "?" for charge in struct.charges],
n_frames,
).tolist()

auth_seq_id = np.tile(struct.resnums.astype(str), n_frames).tolist()
auth_asym_id = np.tile(struct.chains, n_frames).tolist()
pdbx_PDB_model_num = np.concatenate(
Expand All @@ -2651,11 +2680,12 @@ def struct_to_cif_atom_site(struct):
"label_entity_id": label_entity_id,
"label_seq_id": label_seq_id,
"pdbx_PDB_ins_code": pdbx_PDB_ins_code,
"cartn_x": cartn_x,
"cartn_y": cartn_y,
"cartn_z": cartn_z,
"Cartn_x": cartn_x,
"Cartn_y": cartn_y,
"Cartn_z": cartn_z,
"occupancy": occupancy,
"B_iso_or_equiv": B_iso_or_equiv,
"pdbx_formal_charge": formal_charge,
"auth_seq_id": auth_seq_id,
"auth_asym_id": auth_asym_id,
"pdbx_PDB_model_num": pdbx_PDB_model_num,
Expand Down
21 changes: 16 additions & 5 deletions src/chilife/Topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,21 @@ def bonds_from_ccd_data(molsys, ccd_data):

if "chem_comp" in ccd_data[res.resname]:
res_ccd_data = ccd_data[res.resname]["chem_comp"]
if (
pres := res.previous_residue()
) is not None and "link type" in res_ccd_data:
link_type = res_ccd_data["link type"]
linkage_key = (
"type"
if "type" in res_ccd_data
else "link type"
if "link_type" in res_ccd_data
else None
)
if (pres := res.previous_residue()) is not None and linkage_key:
link_type = res_ccd_data["type"].lower()
if link_type in POLYMER_LINKAGE_TYPES:
a1, a2, btype, bchiral = POLYMER_LINKAGE_TYPES[link_type]
i1 = pres.ix[pres.names == a1].flat[0]
i2 = res.ix[res.names == a2].flat[0]
if i1 == 0 and i2 == 1255:
print("break")
bonds.append([i1, i2])
bond_types.append(btype)
bond_chiral.append(bchiral)
Expand Down Expand Up @@ -477,4 +484,8 @@ def numpyify_ccd(ccd_data):


# Linkage data is atom name of the previous residue followed by atom name of the current residue followed by bond type
POLYMER_LINKAGE_TYPES = {"L-peptide linking": ["C", "N", BondType.SINGLE, "N"]}
POLYMER_LINKAGE_TYPES = {
"l-peptide linking": ["C", "N", BondType.SINGLE, "N"],
"peptide linking": ["C", "N", BondType.SINGLE, "N"],
"d-peptide linking": ["C", "N", BondType.SINGLE, "N"],
}
2 changes: 1 addition & 1 deletion src/chilife/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@
# SpinLabel = SpinLabel.SpinLabel
# dSpinLabel = dSpinLabel.dSpinLabel

__version__ = "1.2.1"
__version__ = "1.2.2"
Loading
Loading