Skip to content
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

Fix lll_reduce for slab generation #3927

Merged
merged 49 commits into from
Sep 11, 2024
Merged

Conversation

jinlhr542
Copy link
Contributor

@jinlhr542 jinlhr542 commented Jul 17, 2024

By making the termination identification process for interface generation more robust.

  1. fixing problem for the lll_reduce process when making slabs, doing mapping before updating the structure
  2. allow to set ftol of the termination distances for hierarchical cluster so that some non-identical terminations close to each other can be identified
  3. allow to add index for terminations so that terminations with the same space group can be distinguished
  4. allow to not filter symmetic film and substrate slabs when finding terminations

This reverts commit 70628b4.
1. fixing problem for the lll_reduce process when making slabs, doing mapping before updating the structure
2. allow to set ftol of the termination distances for hierarchical cluster so that some non-identical terminations close to each other can be identified
3. allow to add index for terminations so that terminations with the same space group can be distinguished
1
1
@jinlhr542
Copy link
Contributor Author

@DanielYang59 Sorry, it seems that my changes have conflicts with the recent updates, I remake another pull request using the recent version

@DanielYang59
Copy link
Contributor

DanielYang59 commented Jul 17, 2024

I understand merge conflicts could be confusing but don't worry. Merge conflicts are common things that would happen when you and another person try to make changes to the same line of code. When such things happen, you just need to choose whatever conflict resolver that works best for you (GUI/CLI), and decide what the final conflicted line should end up by yourself.

In most cases, reopen a PR is not necessary, perhaps you could try to resolve them next time when such things happen.

I would ping @janosh for review as I'm not a maintainer and therefore don't have write access to the repo. Can I ask for your patience as he has been quite busy recently? Thank you for your effort towards correcting and improving the code.

@jinlhr542
Copy link
Contributor Author

jinlhr542 commented Jul 17, 2024

Many thanks for the suggestion... I have another issue here. I found that installing the package and by pip install pymatgen by pip install . at the forked folder have different effects. For me, I cannot successfully import the modules like pymatgen.core, pymatgen.analysis etc... by installing the recently released version on 2024.6.10 I forked to local folder. May I have some comments on this issue?
image

@DanielYang59
Copy link
Contributor

I found that installing the package and by pip install pymatgen by pip install . at the forked folder have different effects.

That's exactly right observation. By pip install pymatgen, you are installing pymatgen from PyPI, and by running pip install ., you are instead installing from a local project, refer to this for more details if you are interested.

Meanwhile, if you were trying to contribute to the code, you might want to use pip install --editable . or pip install -e . for short in editable mode, such that your changes to the code could be tested in real time.

For me, I cannot successfully import the modules like pymatgen.core, pymatgen.analysis etc... by installing the recently released version on 2024.6.10 I forked to local folder.

I didn't manage to recreate this issue from my side. Perhaps you should double check if you have a file called pymatgen.py locally which might have shadowed the real pymaygen you are trying to import?

@jinlhr542
Copy link
Contributor Author

Thank you for the explanation but I found the that the reason might be the package is not fully installed, this is the pymatgen folder installed using conda environment... As you can see most of the modules were not successfully installed
image

@DanielYang59
Copy link
Contributor

It's weird, but it's hard to give any advice without seeing the log. Can you show me the log from pip install -e .? Meanwhile I guess it's more readable for me, and easier for you to just copy and paste the terminal outputs. You could also use markdown grammars like triple ``` in both sides of the code to highlight it,or add a collapsible section if the log is too long.

@jinlhr542
Copy link
Contributor Author

(3.11) jason@YaoshuXiedeMacBook-Pro pymatgen % pip install -e .      
Obtaining file:///Users/jason/Documents/GitHub/pymatgen
  Installing build dependencies ... done
  Checking if build backend supports build_editable ... done
  Getting requirements to build editable ... done
  Preparing editable metadata (pyproject.toml) ... done
Requirement already satisfied: matplotlib>=3.8 in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from pymatgen==2024.6.10) (3.9.1)
Requirement already satisfied: monty>=2024.5.24 in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from pymatgen==2024.6.10) (2024.7.12)
Requirement already satisfied: networkx>=2.2 in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from pymatgen==2024.6.10) (3.3)
Requirement already satisfied: palettable>=3.1.1 in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from pymatgen==2024.6.10) (3.3.3)
Requirement already satisfied: pandas>=2 in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from pymatgen==2024.6.10) (2.2.2)
Requirement already satisfied: plotly>=4.5.0 in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from pymatgen==2024.6.10) (5.22.0)
Requirement already satisfied: pybtex>=0.24.0 in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from pymatgen==2024.6.10) (0.24.0)
Requirement already satisfied: requests>=2.32 in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from pymatgen==2024.6.10) (2.32.3)
Requirement already satisfied: ruamel.yaml>=0.17.0 in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from pymatgen==2024.6.10) (0.18.6)
Requirement already satisfied: scipy>=1.13.0 in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from pymatgen==2024.6.10) (1.14.0)
Requirement already satisfied: spglib>=2.5.0 in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from pymatgen==2024.6.10) (2.5.0)
Requirement already satisfied: sympy>=1.2 in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from pymatgen==2024.6.10) (1.13.0)
Requirement already satisfied: tabulate>=0.9 in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from pymatgen==2024.6.10) (0.9.0)
Requirement already satisfied: tqdm>=4.60 in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from pymatgen==2024.6.10) (4.66.4)
Requirement already satisfied: uncertainties>=3.1.4 in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from pymatgen==2024.6.10) (3.2.2)
Requirement already satisfied: joblib>=1 in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from pymatgen==2024.6.10) (1.4.2)
Requirement already satisfied: numpy>=1.25.0 in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from pymatgen==2024.6.10) (1.26.4)
Requirement already satisfied: contourpy>=1.0.1 in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from matplotlib>=3.8->pymatgen==2024.6.10) (1.2.1)
Requirement already satisfied: cycler>=0.10 in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from matplotlib>=3.8->pymatgen==2024.6.10) (0.12.1)
Requirement already satisfied: fonttools>=4.22.0 in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from matplotlib>=3.8->pymatgen==2024.6.10) (4.53.1)
Requirement already satisfied: kiwisolver>=1.3.1 in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from matplotlib>=3.8->pymatgen==2024.6.10) (1.4.5)
Requirement already satisfied: packaging>=20.0 in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from matplotlib>=3.8->pymatgen==2024.6.10) (24.1)
Requirement already satisfied: pillow>=8 in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from matplotlib>=3.8->pymatgen==2024.6.10) (10.4.0)
Requirement already satisfied: pyparsing>=2.3.1 in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from matplotlib>=3.8->pymatgen==2024.6.10) (3.1.2)
Requirement already satisfied: python-dateutil>=2.7 in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from matplotlib>=3.8->pymatgen==2024.6.10) (2.9.0.post0)
Requirement already satisfied: pytz>=2020.1 in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from pandas>=2->pymatgen==2024.6.10) (2024.1)
Requirement already satisfied: tzdata>=2022.7 in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from pandas>=2->pymatgen==2024.6.10) (2024.1)
Requirement already satisfied: tenacity>=6.2.0 in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from plotly>=4.5.0->pymatgen==2024.6.10) (8.5.0)
Requirement already satisfied: PyYAML>=3.01 in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from pybtex>=0.24.0->pymatgen==2024.6.10) (6.0.1)
Requirement already satisfied: latexcodec>=1.0.4 in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from pybtex>=0.24.0->pymatgen==2024.6.10) (3.0.0)
Requirement already satisfied: six in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from pybtex>=0.24.0->pymatgen==2024.6.10) (1.16.0)
Requirement already satisfied: charset-normalizer<4,>=2 in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from requests>=2.32->pymatgen==2024.6.10) (3.3.2)
Requirement already satisfied: idna<4,>=2.5 in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from requests>=2.32->pymatgen==2024.6.10) (3.7)
Requirement already satisfied: urllib3<3,>=1.21.1 in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from requests>=2.32->pymatgen==2024.6.10) (2.2.2)
Requirement already satisfied: certifi>=2017.4.17 in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from requests>=2.32->pymatgen==2024.6.10) (2024.7.4)
Requirement already satisfied: ruamel.yaml.clib>=0.2.7 in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from ruamel.yaml>=0.17.0->pymatgen==2024.6.10) (0.2.8)
Requirement already satisfied: mpmath<1.4,>=1.1.0 in /opt/anaconda3/envs/3.11/lib/python3.11/site-packages (from sympy>=1.2->pymatgen==2024.6.10) (1.3.0)
Building wheels for collected packages: pymatgen
  Building editable for pymatgen (pyproject.toml) ... done
  Created wheel for pymatgen: filename=pymatgen-2024.6.10-0.editable-cp311-cp311-macosx_11_0_arm64.whl size=7492 sha256=2548cfbf6576818aa421af52eb35c4419af329a6ddc25491aefea55384cdd940
  Stored in directory: /private/var/folders/km/tznxn_d162bgzpqpzp9wcjn00000gn/T/pip-ephem-wheel-cache-w9pptfr8/wheels/86/ad/75/5dd22e6df08f3c8b6e3dfe775999afd0464ff20204e3661ff7
Successfully built pymatgen
Installing collected packages: pymatgen
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
emmet-core 0.84.1 requires pymatgen==2024.4.13, but you have pymatgen 2024.6.10 which is incompatible.
Successfully installed pymatgen-2024.6.10```

Indeed there is an issue of the emmet-core dependency problem but it finally says successfully installed...

@DanielYang59
Copy link
Contributor

emmet-core explicitly required pymatgen==2024.4.13 materialsproject/emmet#1020. My suggestion would be creating a separate Python env for developing pymatgen (or any other dedicated task) to avoid such version conflicts.

I believe it's better not to trust an incompletely resolved package dependency?

@jinlhr542
Copy link
Contributor Author

yes, I found the problem. I am using mp-api which requires emmet-core, and emmet-core requires lower version of pymatgen... In this way I can only use the old version pymatgen now... Many thanks for your help there

@janosh janosh force-pushed the master branch 2 times, most recently from e3fbc67 to 41e6d99 Compare August 3, 2024 19:01
Copy link
Member

@janosh janosh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jinlhr542 thanks for these improvements! could you add unit tests for the keywords you added?

jinlhr542 and others added 5 commits August 7, 2024 16:58
…tions for making interface

Interfaces made by identical slabs can be non-identical because the relative transformation of the misorientation and the termination variation do not ensure symmetry, especially when the film and substrate have different point groups. Therefore, the termination finding function should allow to generate all the possible terminations. This can help others to develop more robust algorithm to group the equivalent interfaces made by different terminations.
@jinlhr542
Copy link
Contributor Author

@jinlhr542 thanks for these improvements! could you add unit tests for the keywords you added?

Could you please try this test?

import unittest
from pymatgen.core.structure import Structure
from pymatgen.core.lattice import Lattice
from pymatgen.analysis.interfaces import CoherentInterfaceBuilder, SubstrateAnalyzer

class TestCoherentInterfaceBuilder(unittest.TestCase):

    def setUp(self):
        #build substrate & film structure
        basis = [[0, 0, 0], [0.25, 0.25, 0.25]]
        self.substrate = Structure(
            Lattice.cubic(a=5.431),
            ["Si", "Si"],
            basis)
        self.film = substrate = Structure(
            Lattice.cubic(a=5.658),
            ["Ge", "Ge"],
            basis)

    def test_termination_searching(self):
        sub_analyzer = SubstrateAnalyzer()
        matches = list(sub_analyzer.calculate(substrate = self.substrate, film = self.film))
        cib = CoherentInterfaceBuilder(film_structure = self.film,
                               substrate_structure=self.substrate,
                               film_miller=matches[0].film_miller,
                               substrate_miller=matches[0].substrate_miller,
                               zslgen=sub_analyzer,termination_ftol=1e-4,label_index=True,\
                               filting_out_sym_slabs=False)
        self.assertTrue(cib.terminations == [('1_Ge_P4/mmm_1', '1_Si_P4/mmm_1'),\
                                             ('1_Ge_P4/mmm_1', '2_Si_P4/mmm_1'),\
                                             ('2_Ge_P4/mmm_1', '1_Si_P4/mmm_1'),\
                                             ('2_Ge_P4/mmm_1', '2_Si_P4/mmm_1')], \
"""
termination results wrong; the correct list should be:
[('1_Ge_P4/mmm_1', '1_Si_P4/mmm_1'),
('1_Ge_P4/mmm_1', '2_Si_P4/mmm_1'),
('2_Ge_P4/mmm_1', '1_Si_P4/mmm_1'),
('2_Ge_P4/mmm_1', '2_Si_P4/mmm_1')].
""")

if __name__ == "__main__":
    unittest.main()

@jinlhr542
Copy link
Contributor Author

@jinlhr542 thanks for these improvements! could you add unit tests for the keywords you added?

Dear Janosh

Could you please check the commited tests? It will be appreciated if this pull request can be accepted soon.

Copy link
Member

@janosh janosh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor variable rename suggestions

src/pymatgen/core/surface.py Outdated Show resolved Hide resolved
@@ -2838,8 +2838,14 @@ def from_slabs(
return iface


def label_termination(slab: Structure) -> str:
"""Label the slab surface termination."""
def label_termination(slab: Structure, ftol: float = 0.25, t_index: int | None = None) -> str:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about just tol instead of ftol? does the f have any meaning? also, how about t_index->t_idx for brevity?

Suggested change
def label_termination(slab: Structure, ftol: float = 0.25, t_index: int | None = None) -> str:
def label_termination(slab: Structure, ftol: float = 0.25, t_index: int | None = None) -> str:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f means flat cluster, to be consistent with the ftol argument of the get_slabs() function in the SlabGenerator class

@jinlhr542
Copy link
Contributor Author

jinlhr542 commented Sep 9, 2024

minor variable rename suggestions

Modified accordingly, please review again.

label_index: whether to add an extra index at the beginning of the termination label.
filter_out_sym_slabs: whether to filter out identical slabs with different termination,
this might need to be set as False to find more non-identical terminations because slab
identity separately dose not mean combinational identity.
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you clarify/rephrase "identity separately does not mean combinational identity". combinational is a rare word. do you mean identity of slab + termination?

Copy link
Contributor Author

@jinlhr542 jinlhr542 Sep 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specifically, for two combinations (A1, B1) and (A2, B2). 'A1 equal to A2' and 'B1 equal to B2' does not always make (A1, B2) equal to (A2, B2). When making two interfaces if the two set of slabs are related by certain symmetry operations respectively, these operations need to be compatible to make a 'combinational' identity thus identical interfaces.

@janosh janosh added fix Bug fix PRs surfaces Surface analysis labels Sep 9, 2024
@janosh janosh changed the title fixing lll_reduce for slab generation and making the termination identification process for interface generation more robust. Fix lll_reduce for slab generation Sep 9, 2024
Copy link
Member

@janosh janosh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks a lot @jinlhr542! 👍

@janosh janosh merged commit 6bb2938 into materialsproject:master Sep 11, 2024
43 checks passed
@DanielYang59
Copy link
Contributor

@jinlhr542 Great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix PRs surfaces Surface analysis
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants