Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
FastFold
Commits
7a449372
"src/git@developer.sourcefind.cn:chenpangpang/open-webui.git" did not exist on "6ba62cf25d07300d8bca2ea41d37a0823e4f96f8"
Unverified
Commit
7a449372
authored
Sep 13, 2022
by
Fazzie-Maqianli
Committed by
GitHub
Sep 13, 2022
Browse files
bug fix (#64)
parent
4693058b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
178 additions
and
7 deletions
+178
-7
fastfold/common/residue_constants.py
fastfold/common/residue_constants.py
+177
-1
fastfold/utils/all_atom_multimer.py
fastfold/utils/all_atom_multimer.py
+1
-6
No files found.
fastfold/common/residue_constants.py
View file @
7a449372
...
@@ -1314,3 +1314,179 @@ def aatype_to_str_sequence(aatype):
...
@@ -1314,3 +1314,179 @@ def aatype_to_str_sequence(aatype):
restypes_with_x
[
aatype
[
i
]]
restypes_with_x
[
aatype
[
i
]]
for
i
in
range
(
len
(
aatype
))
for
i
in
range
(
len
(
aatype
))
])
])
### ALPHAFOLD MULTIMER STUFF ###
def
_make_chi_atom_indices
():
"""Returns atom indices needed to compute chi angles for all residue types.
Returns:
A tensor of shape [residue_types=21, chis=4, atoms=4]. The residue types are
in the order specified in residue_constants.restypes + unknown residue type
at the end. For chi angles which are not defined on the residue, the
positions indices are by default set to 0.
"""
chi_atom_indices
=
[]
for
residue_name
in
restypes
:
residue_name
=
restype_1to3
[
residue_name
]
residue_chi_angles
=
chi_angles_atoms
[
residue_name
]
atom_indices
=
[]
for
chi_angle
in
residue_chi_angles
:
atom_indices
.
append
(
[
atom_order
[
atom
]
for
atom
in
chi_angle
])
for
_
in
range
(
4
-
len
(
atom_indices
)):
atom_indices
.
append
([
0
,
0
,
0
,
0
])
# For chi angles not defined on the AA.
chi_atom_indices
.
append
(
atom_indices
)
chi_atom_indices
.
append
([[
0
,
0
,
0
,
0
]]
*
4
)
# For UNKNOWN residue.
return
np
.
array
(
chi_atom_indices
)
def
_make_renaming_matrices
():
"""Matrices to map atoms to symmetry partners in ambiguous case."""
# As the atom naming is ambiguous for 7 of the 20 amino acids, provide
# alternative groundtruth coordinates where the naming is swapped
restype_3
=
[
restype_1to3
[
res
]
for
res
in
restypes
]
restype_3
+=
[
'UNK'
]
# Matrices for renaming ambiguous atoms.
all_matrices
=
{
res
:
np
.
eye
(
14
,
dtype
=
np
.
float32
)
for
res
in
restype_3
}
for
resname
,
swap
in
residue_atom_renaming_swaps
.
items
():
correspondences
=
np
.
arange
(
14
)
for
source_atom_swap
,
target_atom_swap
in
swap
.
items
():
source_index
=
restype_name_to_atom14_names
[
resname
].
index
(
source_atom_swap
)
target_index
=
restype_name_to_atom14_names
[
resname
].
index
(
target_atom_swap
)
correspondences
[
source_index
]
=
target_index
correspondences
[
target_index
]
=
source_index
renaming_matrix
=
np
.
zeros
((
14
,
14
),
dtype
=
np
.
float32
)
for
index
,
correspondence
in
enumerate
(
correspondences
):
renaming_matrix
[
index
,
correspondence
]
=
1.
all_matrices
[
resname
]
=
renaming_matrix
.
astype
(
np
.
float32
)
renaming_matrices
=
np
.
stack
([
all_matrices
[
restype
]
for
restype
in
restype_3
])
return
renaming_matrices
def
_make_restype_atom37_mask
():
"""Mask of which atoms are present for which residue type in atom37."""
# create the corresponding mask
restype_atom37_mask
=
np
.
zeros
([
21
,
37
],
dtype
=
np
.
float32
)
for
restype
,
restype_letter
in
enumerate
(
restypes
):
restype_name
=
restype_1to3
[
restype_letter
]
atom_names
=
residue_atoms
[
restype_name
]
for
atom_name
in
atom_names
:
atom_type
=
atom_order
[
atom_name
]
restype_atom37_mask
[
restype
,
atom_type
]
=
1
return
restype_atom37_mask
def
_make_restype_atom14_mask
():
"""Mask of which atoms are present for which residue type in atom14."""
restype_atom14_mask
=
[]
for
rt
in
restypes
:
atom_names
=
restype_name_to_atom14_names
[
restype_1to3
[
rt
]]
restype_atom14_mask
.
append
([(
1.
if
name
else
0.
)
for
name
in
atom_names
])
restype_atom14_mask
.
append
([
0.
]
*
14
)
restype_atom14_mask
=
np
.
array
(
restype_atom14_mask
,
dtype
=
np
.
float32
)
return
restype_atom14_mask
def
_make_restype_atom37_to_atom14
():
"""Map from atom37 to atom14 per residue type."""
restype_atom37_to_atom14
=
[]
# mapping (restype, atom37) --> atom14
for
rt
in
restypes
:
atom_names
=
restype_name_to_atom14_names
[
restype_1to3
[
rt
]]
atom_name_to_idx14
=
{
name
:
i
for
i
,
name
in
enumerate
(
atom_names
)}
restype_atom37_to_atom14
.
append
([
(
atom_name_to_idx14
[
name
]
if
name
in
atom_name_to_idx14
else
0
)
for
name
in
atom_types
])
restype_atom37_to_atom14
.
append
([
0
]
*
37
)
restype_atom37_to_atom14
=
np
.
array
(
restype_atom37_to_atom14
,
dtype
=
np
.
int32
)
return
restype_atom37_to_atom14
def
_make_restype_atom14_to_atom37
():
"""Map from atom14 to atom37 per residue type."""
restype_atom14_to_atom37
=
[]
# mapping (restype, atom14) --> atom37
for
rt
in
restypes
:
atom_names
=
restype_name_to_atom14_names
[
restype_1to3
[
rt
]]
restype_atom14_to_atom37
.
append
([
(
atom_order
[
name
]
if
name
else
0
)
for
name
in
atom_names
])
# Add dummy mapping for restype 'UNK'
restype_atom14_to_atom37
.
append
([
0
]
*
14
)
restype_atom14_to_atom37
=
np
.
array
(
restype_atom14_to_atom37
,
dtype
=
np
.
int32
)
return
restype_atom14_to_atom37
def
_make_restype_atom14_is_ambiguous
():
"""Mask which atoms are ambiguous in atom14."""
# create an ambiguous atoms mask. shape: (21, 14)
restype_atom14_is_ambiguous
=
np
.
zeros
((
21
,
14
),
dtype
=
np
.
float32
)
for
resname
,
swap
in
residue_atom_renaming_swaps
.
items
():
for
atom_name1
,
atom_name2
in
swap
.
items
():
restype
=
restype_order
[
restype_3to1
[
resname
]]
atom_idx1
=
restype_name_to_atom14_names
[
resname
].
index
(
atom_name1
)
atom_idx2
=
restype_name_to_atom14_names
[
resname
].
index
(
atom_name2
)
restype_atom14_is_ambiguous
[
restype
,
atom_idx1
]
=
1
restype_atom14_is_ambiguous
[
restype
,
atom_idx2
]
=
1
return
restype_atom14_is_ambiguous
def
_make_restype_rigidgroup_base_atom37_idx
():
"""Create Map from rigidgroups to atom37 indices."""
# Create an array with the atom names.
# shape (num_restypes, num_rigidgroups, 3_atoms): (21, 8, 3)
base_atom_names
=
np
.
full
([
21
,
8
,
3
],
''
,
dtype
=
object
)
# 0: backbone frame
base_atom_names
[:,
0
,
:]
=
[
'C'
,
'CA'
,
'N'
]
# 3: 'psi-group'
base_atom_names
[:,
3
,
:]
=
[
'CA'
,
'C'
,
'O'
]
# 4,5,6,7: 'chi1,2,3,4-group'
for
restype
,
restype_letter
in
enumerate
(
restypes
):
resname
=
restype_1to3
[
restype_letter
]
for
chi_idx
in
range
(
4
):
if
chi_angles_mask
[
restype
][
chi_idx
]:
atom_names
=
chi_angles_atoms
[
resname
][
chi_idx
]
base_atom_names
[
restype
,
chi_idx
+
4
,
:]
=
atom_names
[
1
:]
# Translate atom names into atom37 indices.
lookuptable
=
atom_order
.
copy
()
lookuptable
[
''
]
=
0
restype_rigidgroup_base_atom37_idx
=
np
.
vectorize
(
lambda
x
:
lookuptable
[
x
])(
base_atom_names
)
return
restype_rigidgroup_base_atom37_idx
CHI_ATOM_INDICES
=
_make_chi_atom_indices
()
RENAMING_MATRICES
=
_make_renaming_matrices
()
RESTYPE_ATOM14_TO_ATOM37
=
_make_restype_atom14_to_atom37
()
RESTYPE_ATOM37_TO_ATOM14
=
_make_restype_atom37_to_atom14
()
RESTYPE_ATOM37_MASK
=
_make_restype_atom37_mask
()
RESTYPE_ATOM14_MASK
=
_make_restype_atom14_mask
()
RESTYPE_ATOM14_IS_AMBIGUOUS
=
_make_restype_atom14_is_ambiguous
()
RESTYPE_RIGIDGROUP_BASE_ATOM37_IDX
=
_make_restype_rigidgroup_base_atom37_idx
()
# Create mask for existing rigid groups.
RESTYPE_RIGIDGROUP_MASK
=
np
.
zeros
([
21
,
8
],
dtype
=
np
.
float32
)
RESTYPE_RIGIDGROUP_MASK
[:,
0
]
=
1
RESTYPE_RIGIDGROUP_MASK
[:,
3
]
=
1
RESTYPE_RIGIDGROUP_MASK
[:
20
,
4
:]
=
chi_angles_mask
fastfold/utils/all_atom_multimer.py
View file @
7a449372
...
@@ -18,12 +18,7 @@ from typing import Dict, Text, Tuple
...
@@ -18,12 +18,7 @@ from typing import Dict, Text, Tuple
import
torch
import
torch
from
fastfold.common
import
residue_const
from
fastfold.common
import
residue_constants
as
rc
ants
as
rc
from
fastfold.utils
import
geometry
,
tensor_utils
from
fastfold.utils
import
geometry
,
tensor_utils
import
numpy
as
np
import
numpy
as
np
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment