Skip to content

Commit

Permalink
support altloc in PDBparser
Browse files Browse the repository at this point in the history
  • Loading branch information
minhuanli committed Oct 3, 2024
1 parent 611e986 commit a99b748
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions SFC_Torch/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def hier2array(structure):
atom_b_aniso = []
atom_b_iso = []
atom_occ = []
atom_altloc = []
res_id = []
i = 0
model = structure[i] # gemmi.Model object
Expand Down Expand Up @@ -49,18 +50,20 @@ def hier2array(structure):
atom_b_iso.append(atom.b_iso)
# A list of occupancy [P1,P2,....], [Nc]
atom_occ.append(atom.occ)
# A list of altloc label
atom_altloc.append(atom.altloc)
# A list of residue id
res_id.append(res.seqid.num)
j += 1
atom_pos = np.array(atom_pos)
atom_b_aniso = np.array(atom_b_aniso)
atom_b_iso = np.array(atom_b_iso)
atom_occ = np.array(atom_occ)
return atom_pos, atom_b_aniso, atom_b_iso, atom_occ, atom_name, cra_name, res_id
return atom_pos, atom_b_aniso, atom_b_iso, atom_occ, atom_name, cra_name, atom_altloc, res_id


def array2hier(
atom_pos, atom_b_aniso, atom_b_iso, atom_occ, atom_name, cra_name, res_id
atom_pos, atom_b_aniso, atom_b_iso, atom_occ, atom_name, cra_name, atom_altloc, res_id
):
new_model = gemmi.Model("SFC")
for i in range(len(cra_name)):
Expand Down Expand Up @@ -88,6 +91,7 @@ def array2hier(
current_atom.b_iso = atom_b_iso[i]
current_atom.pos = gemmi.Position(*atom_pos[i])
current_atom.occ = atom_occ[i]
current_atom.altloc = atom_altloc[i]

current_res.add_atom(current_atom)

Expand Down Expand Up @@ -129,6 +133,7 @@ def __init__(self, data):
self.atom_occ,
self.atom_name,
self.cra_name,
self.atom_altloc,
self.res_id,
) = hier2array(structure)
try:
Expand Down Expand Up @@ -166,6 +171,7 @@ def to_gemmi(self, include_header=True):
self.atom_occ,
self.atom_name,
self.cra_name,
self.atom_altloc,
self.res_id,
)
st.spacegroup_hm = self.spacegroup.hm
Expand Down Expand Up @@ -293,6 +299,7 @@ def selection(self, condition, inplace=False):
self.atom_occ,
self.atom_name,
self.cra_name,
self.atom_altloc,
self.res_id,
) = hier2array(sele_st)
else:
Expand All @@ -313,6 +320,7 @@ def from_atom_slices(self, atom_slices, inplace=False):
self.atom_occ = self.atom_occ[atom_slices]
self.atom_name = [self.atom_name[i] for i in atom_slices]
self.cra_name = [self.cra_name[i] for i in atom_slices]
self.atom_altloc = [self.atom_altloc[i] for i in atom_slices]
self.res_id = [self.res_id[i] for i in atom_slices]
else:
st = array2hier(
Expand All @@ -322,6 +330,7 @@ def from_atom_slices(self, atom_slices, inplace=False):
self.atom_occ[atom_slices],
[self.atom_name[i] for i in atom_slices],
[self.cra_name[i] for i in atom_slices],
[self.atom_altloc[i] for i in atom_slices],
[self.res_id[i] for i in atom_slices],
)
st.spacegroup_hm = self.spacegroup.hm
Expand Down

0 comments on commit a99b748

Please sign in to comment.