Skip to content

Commit

Permalink
Merge pull request #70 from 3dem/mmcifio-fix
Browse files Browse the repository at this point in the history
Mmcifio fix
  • Loading branch information
jamaliki authored Sep 25, 2023
2 parents b69278d + 56c962c commit a65581e
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 32 deletions.
3 changes: 1 addition & 2 deletions install_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ then
exit 1;
fi

conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia
conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia -y

if [ "${torch_home_path}" ]
then
Expand All @@ -51,7 +51,6 @@ fi

python_exc="${CONDA_PREFIX}/bin/python"

$python_exc -mpip install -r requirements.txt
$python_exc setup.py install

if [[ "${DOWNLOAD_WEIGHTS}" ]]; then
Expand Down
2 changes: 1 addition & 1 deletion model_angelo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
"""


__version__ = "1.0.1"
__version__ = "1.0.2"
43 changes: 24 additions & 19 deletions model_angelo/utils/save_pdb_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
import os
import pickle
from typing import List, Union
from copy import deepcopy

import numpy as np
import pandas as pd
from Bio.PDB.mmcifio import MMCIFIO
from Bio.PDB.StructureBuilder import StructureBuilder

from model_angelo.utils.misc_utils import assertion_check
from model_angelo.utils.protein import Protein, frames_and_literature_positions_to_atomc_pos, \
from model_angelo.utils.protein import Protein, \
frames_and_literature_positions_to_atom3_pos
from model_angelo.utils.residue_constants import (
index_to_restype_3,
Expand All @@ -24,6 +25,16 @@
SEQUENCE_BASED_CHAIN_IDS = "abcdefghijklmnopqrstuvwxyz0123456789"



class ModelAngeloMMCIFIO(MMCIFIO):
def _save_dict(self, out_file):
auth_seq_id = deepcopy(self.dic["_atom_site.label_seq_id"])
label_seq_id = deepcopy(self.dic["_atom_site.auth_seq_id"])
self.dic["_atom_site.label_seq_id"] = label_seq_id
self.dic["_atom_site.auth_seq_id"] = auth_seq_id
return super()._save_dict(out_file)


def number_to_base(n, b):
"""
From https://stackoverflow.com/questions/2267362/how-to-convert-an-integer-to-a-string-in-any-base
Expand Down Expand Up @@ -69,6 +80,12 @@ 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 = ModelAngeloMMCIFIO()
io.set_structure(structure)
io.save(path_to_save)


def points_to_pdb(path_to_save, points):
struct = StructureBuilder()
struct.init_structure("1")
Expand All @@ -80,9 +97,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 +133,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 +148,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 +219,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 +289,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 +370,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
10 changes: 0 additions & 10 deletions requirements.txt

This file was deleted.

12 changes: 12 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,16 @@
},
package_data={'': ['utils/stereo_chemical_props.txt']},
version=model_angelo.__version__,
install_requires=[
"tqdm",
"scipy",
"biopython>=1.81",
"einops",
"matplotlib",
"mrcfile",
"pandas",
"fair-esm",
"pyhmmer>=0.10.1",
"loguru",
],
)
2 changes: 2 additions & 0 deletions test/bc3-new.fasta
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
>5UDE_1|Chain A[auth F]|Fusion glycoprotein F0|Human Respiratory syncytial virus 9320 (253182)
MKCLLYLAFLFIGVNCQNITEEFYQSTCSAVSRGYFSALRTGWYTSVITIELSNIKEPKCNGTDTKVKLIKQELDKYKNAVTELQLLMQSGGPGSGGGGSGGGGSRFPPFPLGVGSAIASGIAVSKVLHLPGEVNKIKNALLSTNKAVVSLSNGVSVLTSKVLDLKNYINNQLLPIVNQQSCRISNIETVIEFQQKNSRLLEITREFSVNAGVTTPLSTYMLTNSELLSLINDMPITNDQKKLMSSNVPIVRQQSYSIMSIIKEEVLAYVVQLPIYGVIDTPCWKLHTSPLCTTNIKEGSNICLTRTDRGWYCDNAGSVSFFPQADTCKVQSNRVFCDTMNSLTLPPEVSLCNTDIFNSKYDCKIMTSKTDISSSVITSLGAIVSCYGKTKCTASNKNRGIIKTFSNGCDYVSNKGVDTVSVGNTLYYVNKLEGKNLYVKGEPIINYYDPLVFPSDEFDASISQVNEKINQSLAFIRRSDELLGSGYIPEAPRDGQAYVRKDGEWVLLSTFLG
Binary file added test/cryosparc_P3_J345_map.mrc
Binary file not shown.

0 comments on commit a65581e

Please sign in to comment.