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

Fix for issue #51 #63

Merged
merged 1 commit into from
Aug 22, 2023
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
36 changes: 18 additions & 18 deletions model_angelo/utils/save_pdb_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import pickle
from typing import List, Union
from copy import deepcopy

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -69,6 +70,17 @@ def points_to_xyz(path_to_save, points, zyx_order=False):
f.write(f"C {point[2]} {point[1]} {point[0]}\n")


def save_structure_to_cif(structure, path_to_save: str):
io = MMCIFIO()
io.set_structure(structure)
# These are switched, as pointed out by Tristan Croll
auth_seq_id = deepcopy(io.dic["_atom_site.label_seq_id"])
label_seq_id = deepcopy(io.dic["_atom_site.auth_seq_id"])
io.dic["_atom_site.label_seq_id"] = label_seq_id
io.dic["_atom_site.auth_seq_id"] = auth_seq_id
io.save(path_to_save)


def points_to_pdb(path_to_save, points):
struct = StructureBuilder()
struct.init_structure("1")
Expand All @@ -80,9 +92,7 @@ def points_to_pdb(path_to_save, points):
struct.init_residue(f"ALA", " ", i, " ")
struct.init_atom("CA", point, 0, 1, " ", "CA", "C")
struct = struct.get_structure()
io = MMCIFIO()
io.set_structure(struct)
io.save(path_to_save)
save_structure_to_cif(struct, path_to_save)


def ca_ps_to_pdb(path_to_save, ca_points, p_points):
Expand Down Expand Up @@ -118,9 +128,7 @@ def ca_ps_to_pdb(path_to_save, ca_points, p_points):
element="P",
)
struct = struct.get_structure()
io = MMCIFIO()
io.set_structure(struct)
io.save(path_to_save)
save_structure_to_cif(struct, path_to_save)


def chains_to_pdb(path_to_save, chains):
Expand All @@ -135,9 +143,7 @@ def chains_to_pdb(path_to_save, chains):
struct.init_residue(f"ALA", " ", j, " ")
struct.init_atom("CA", point, 0, 1, " ", "CA", "C")
struct = struct.get_structure()
io = MMCIFIO()
io.set_structure(struct)
io.save(path_to_save)
save_structure_to_cif(struct, path_to_save)


def to_xyz(directory):
Expand Down Expand Up @@ -208,9 +214,7 @@ def atom14_to_cif(
)
res_counter += 1
struct = struct.get_structure()
io = MMCIFIO()
io.set_structure(struct)
io.save(path_to_save)
save_structure_to_cif(struct, path_to_save)


def protein_to_cif(
Expand Down Expand Up @@ -280,9 +284,7 @@ def protein_to_cif(
)
res_counter += 1
struct = struct.get_structure()
io = MMCIFIO()
io.set_structure(struct)
io.save(path_to_save)
save_structure_to_cif(struct, path_to_save)


def chain_atom14_to_cif(
Expand Down Expand Up @@ -363,9 +365,7 @@ def chain_atom14_to_cif(
res_counter += 1

struct = struct.get_structure()
io = MMCIFIO()
io.set_structure(struct)
io.save(path_to_save)
save_structure_to_cif(struct, path_to_save)


def write_chain_report(
Expand Down