-
Notifications
You must be signed in to change notification settings - Fork 907
Add Structure.sublattices
and class RandomStructureTransformation
to standard_transformations.py
#3057
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
base: master
Are you sure you want to change the base?
Add Structure.sublattices
and class RandomStructureTransformation
to standard_transformations.py
#3057
Changes from 4 commits
2398a05
72924bf
f77b6c0
450c47d
7a4815b
7d9cab8
eb793ae
dfc74e4
20928c7
5449ed0
84f7832
353da7f
47869a7
4e8fea7
e0f40f7
3a2ebc7
b72f962
24d9689
3285df6
5f0550a
81dd21b
a8defc1
9b84cc2
766f062
5d6f238
e32fd8f
4591156
5f1de0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,10 @@ | |
|
||
logger = logging.getLogger(__name__) | ||
|
||
import random | ||
|
||
import numpy as np | ||
|
||
|
||
class RotationTransformation(AbstractTransformation): | ||
""" | ||
|
@@ -494,6 +498,82 @@ def inverse(self): | |
return | ||
|
||
|
||
class RandomStructureTransformation(AbstractTransformation): | ||
def __init__(self): | ||
pass | ||
exenGT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def apply_transformation(self, structure: Structure, num_copies: int): | ||
exenGT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
For this transformation, the apply_transformation method will return | ||
a random ordered structure from the given disordered structure. | ||
""" | ||
subl = structure.sublattices | ||
|
||
# fill the sublattice sites with pure-element atoms | ||
self.all_structures = [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it necessary to store the structures on the transformation instance? might balloon mem usage if people create many of these There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used this syntax because there is an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there's no connection between There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you elaborate more on this? I feel I'm not totally understanding. For example, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you explain the need to store all structures for later? Why not just return them and let them be garbage collected if they go out of scope in the user's code? Currently they live as long as the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. This feature is here simply because I'm copying what's been written for the other transformations. If you think it's not a good approach, then I can modify it in my code accordingly. |
||
|
||
for _ in range(num_copies): | ||
new_structure = structure.copy() | ||
|
||
for subl_comp, subl_indices in subl.items(): | ||
# convert composition into a dictionary | ||
subl_comp_dict = subl_comp.as_dict() | ||
|
||
el_list = list(subl_comp_dict.keys()) | ||
el_concs = np.array(list(subl_comp_dict.values())) | ||
|
||
# randomly choose site indices for each element present in the sublattice | ||
|
||
el_indices = self.random_assign( | ||
sequence=subl_indices, lengths=(el_concs * len(subl_indices)).astype(int) | ||
) | ||
|
||
for i_el, el in enumerate(el_list): | ||
new_structure[el_indices[i_el]] = el | ||
|
||
self.all_structures.append(new_structure) | ||
|
||
return self.all_structures | ||
|
||
@property | ||
def inverse(self): | ||
""" | ||
Returns: None | ||
""" | ||
return | ||
|
||
@property | ||
def is_one_to_many(self) -> bool: | ||
""" | ||
Returns: True | ||
""" | ||
return True | ||
|
||
def random_assign(self, sequence: list[int], lengths: list[int]) -> list[int]: | ||
""" | ||
Randomly assign sublists in sequence with given lengths | ||
exenGT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
random.shuffle(sequence) | ||
|
||
assignments = [] | ||
|
||
start_pos = 0 | ||
|
||
for length in lengths: | ||
end_pos = min(start_pos + length, len(sequence)) | ||
|
||
## check if end_pos is greater than start_pos | ||
if end_pos > start_pos: | ||
assignments.append(sequence[start_pos:end_pos]) | ||
start_pos = end_pos | ||
|
||
else: | ||
print("Sum of lengths must be equal to the length of the sequence!") | ||
exenGT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return -1 | ||
|
||
return assignments | ||
|
||
|
||
class OrderDisorderedStructureTransformation(AbstractTransformation): | ||
""" | ||
Order a disordered structure. The disordered structure must be oxidation | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,4 @@ f90nml>=1.4.3 | |
seekpath>=2.0.1 | ||
jarvis-tools>=2022.9.16 | ||
galore>=0.7.0 | ||
matgl>=0.5.1 | ||
matgl>=0.5.1 |
Uh oh!
There was an error while loading. Please reload this page.