Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
CodeRed
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
M-29
Software
CodeRed
Commits
a18d4d61
Commit
a18d4d61
authored
4 years ago
by
Kai Sellschopp
Browse files
Options
Downloads
Patches
Plain Diff
added first bits to include a scheme for selecting structures based on their representation
parent
94442541
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
new/codered.py
+14
-8
14 additions, 8 deletions
new/codered.py
new/representations.py
+25
-6
25 additions, 6 deletions
new/representations.py
with
39 additions
and
14 deletions
new/codered.py
+
14
−
8
View file @
a18d4d61
...
...
@@ -275,7 +275,7 @@ class CodeRed:
return
def
red
(
self
,
red_type
=
None
,
surface
=
'
reduced
'
,
representation
=
"
positions
"
,
representation_params
=
{},
select
ion
=
"
symmetry
"
,
select
ion
_params
=
{},
**
reduction_params
):
def
red
(
self
,
red_type
=
None
,
surface
=
'
reduced
'
,
representation
=
None
,
representation_params
=
{},
select
or
=
None
,
select
or
_params
=
{},
**
reduction_params
):
#TODO: process reduction_params to set up and execute the right reduction technique
# e.g. symmetry reduction, mesh projection reduction, soap distance reduction, ...
...
...
@@ -288,7 +288,9 @@ class CodeRed:
structures
=
self
.
structures
.
copy
()
# transform structures according to representation setting
if
representation
in
[
"
positions
"
,
"
pos
"
,
"
coordinates
"
]:
if
representation
==
None
:
structures_repr
=
structures
.
copy
()
elif
representation
in
[
"
positions
"
,
"
pos
"
,
"
coordinates
"
]:
structures_repr
=
representations
.
positions
(
structures
,
**
representation_params
)
elif
representation
in
[
"
box
"
,
"
boxes
"
,
"
boxgrid
"
,
"
grid
"
]:
structures_repr
=
representations
.
boxgrid
(
structures
,
**
representation_params
)
...
...
@@ -299,6 +301,16 @@ class CodeRed:
print
(
"
This is not a valid representation!
"
)
raise
# get a structure selection from the selector
if
selector
==
None
:
selection
=
np
.
ones
(
len
(
self
.
structures
),
dtype
=
'
bool
'
)
else
:
try
:
selection
=
selector
(
structures_repr
,
**
selection_params
)
except
TypeError
:
print
(
"
This is not a valid selector!
"
)
raise
## perform reduction according to the set reduction type
#if red_type=='symmetry':
# # generate informative output
...
...
@@ -322,12 +334,6 @@ class CodeRed:
# if red_array[i]:
# structures_new.append(self.structures[i])
#
#elif red_type=='sidechains':
# # generate informative output
# print("Generating side chains and corresponding minimum distance reduction...")
#
# # generate structures including side chains
# structures_new = self.make_sidechains()
# save reduced structure list
self
.
structures
=
structures_new
...
...
This diff is collapsed.
Click to expand it.
new/representations.py
+
25
−
6
View file @
a18d4d61
...
...
@@ -17,7 +17,7 @@ def positions(structures, cartesian=False):
return
representation
def
boxgrid
(
structures
,
n_boxes_a
=
1
,
n_boxes_b
=
1
,
n_boxes_c
=
1
,
cartesian
=
False
):
def
boxgrid
(
structures
,
n_boxes_a
=
1
,
n_boxes_b
=
1
,
n_boxes_c
=
1
,
cartesian
=
False
,
return_structures
=
False
):
"""
This representation splits the bounding box of the structures into a grid of
boxes and represents each position by the center of the sub-box it is in.
...
...
@@ -44,8 +44,27 @@ def boxgrid(structures, n_boxes_a=1, n_boxes_b=1, n_boxes_c=1, cartesian=False):
grid
=
np
.
array
([
grid_aa
,
grid_bb
,
grid_cc
]).
reshape
(
3
,
len
(
ga
)
*
len
(
gb
)
*
len
(
gc
)).
T
# project positions on the grid
representation
=
np
.
copy
(
positions
).
reshape
(
-
1
,
3
)
for
i
in
range
(
len
(
representation
)):
representation
[
i
]
=
grid
[
np
.
argmin
(
np
.
linalg
.
norm
(
grid
-
representation
[
i
],
axis
=-
1
))]
return
representation
.
reshape
(
positions
.
shape
)
projections
=
np
.
copy
(
positions
).
reshape
(
-
1
,
3
)
for
i
in
range
(
len
(
projections
)):
projections
[
i
]
=
grid
[
np
.
argmin
(
np
.
linalg
.
norm
(
grid
-
projections
[
i
],
axis
=-
1
))]
# transform to desired output
if
return_structures
:
# reshape to fit (N_structures, N_atoms, 3) shape
new_positions
=
projections
.
reshape
(
positions
.
shape
)
representation
=
[]
for
i
in
range
(
len
(
structures
)):
copy
=
structures
[
i
].
copy
()
# set cartesian or relative coordinates
if
cartesian
:
copy
.
set_positions
(
new_positions
[
i
])
else
:
copy
.
set_scaled_positions
(
new_positions
[
i
])
# add to representation list
representation
.
append
(
copy
)
else
:
# reshape to fit (N_structures, N_atoms, 3) shape
representation
=
projections
.
reshape
(
positions
.
shape
)
return
representation
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment