Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow loading computationally predicted cif files, which may not have certain custom annotations #670

Merged
Merged
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
45 changes: 41 additions & 4 deletions src/biotite/structure/io/pdbx/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,16 +480,53 @@ def _fill_annotations(array, atom_site, extra_fields, use_author_fields):
array.set_annotation("element", atom_site["type_symbol"].as_array(str))

if "atom_id" in extra_fields:
array.set_annotation("atom_id", atom_site["id"].as_array(int))
if "id" in atom_site:
array.set_annotation("atom_id", atom_site["id"].as_array(int))
else:
warnings.warn(
"Missing 'id' in 'atom_site' category. 'atom_id' generated automatically.",
UserWarning,
)
array.set_annotation("atom_id", np.arange(array.array_length()))
extra_fields.remove("atom_id")
if "b_factor" in extra_fields:
array.set_annotation("b_factor", atom_site["B_iso_or_equiv"].as_array(float))
if "B_iso_or_equiv" in atom_site:
array.set_annotation(
"b_factor", atom_site["B_iso_or_equiv"].as_array(float)
)
else:
warnings.warn(
"Missing 'B_iso_or_equiv' in 'atom_site' category. 'b_factor' will be set to `nan`.",
UserWarning,
)
array.set_annotation("b_factor", np.full(array.array_length(), np.nan))
extra_fields.remove("b_factor")
if "occupancy" in extra_fields:
array.set_annotation("occupancy", atom_site["occupancy"].as_array(float))
if "occupancy" in atom_site:
array.set_annotation("occupancy", atom_site["occupancy"].as_array(float))
else:
warnings.warn(
"Missing 'occupancy' in 'atom_site' category. 'occupancy' will be assumed to be 1.0",
UserWarning,
)
array.set_annotation(
"occupancy", np.ones(array.array_length(), dtype=float)
)
extra_fields.remove("occupancy")
if "charge" in extra_fields:
array.set_annotation("charge", atom_site["pdbx_formal_charge"].as_array(int, 0))
if "pdbx_formal_charge" in atom_site:
array.set_annotation(
"charge",
atom_site["pdbx_formal_charge"].as_array(
int, 0
), # masked values are set to 0
)
else:
warnings.warn(
"Missing 'pdbx_formal_charge' in 'atom_site' category. 'charge' will be set to 0",
UserWarning,
)
array.set_annotation("charge", np.zeros(array.array_length(), dtype=int))
extra_fields.remove("charge")

# Handle all remaining custom fields
Expand Down
Loading