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

[BUG] Crystal supercell displays in a very weird way #770

Open
fxcoudert opened this issue Feb 23, 2024 · 10 comments
Open

[BUG] Crystal supercell displays in a very weird way #770

fxcoudert opened this issue Feb 23, 2024 · 10 comments
Labels

Comments

@fxcoudert
Copy link

Describe the bug
Loading a CIF file with symmetry and duplicating the unit cell gives this:

Capture d’écran 2024-02-23 à 18 48 06

To Reproduce
I've put an example online at https://www.nanoporous.net/MOF_viewer/

  1. Select HKUST-1 P1
  2. Then select HKUST-1 with symmetry
  3. See the difference

Both files represent exactly the same structure, one has symmetry information.

Expected behavior
The full code is in the webpage source. The loading code is this:

        v.clear();
        let m = v.addModel(data, 'cif', {doAssembly: true, duplicateAssemblyAtoms: true, normalizeAssembly: true});
        v.addUnitCell(m, {box: {color: 'purple'}, alabel: 'a', blabel: 'b', clabel: 'c'});
        v.setStyle({stick: {colorscheme: 'Jmol'}});
        v.replicateUnitCell(2, 2, 2, m, true);
        v.setProjection('orthographic');
        v.zoomTo();                          /* set camera */
        v.render();                          /* render scene */
        v.zoom(1.8, 1000);                   /* slight zoom */

and the two relevant lines are:

        let m = v.addModel(data, 'cif', {doAssembly: true, duplicateAssemblyAtoms: true, normalizeAssembly: true});
        v.replicateUnitCell(2, 2, 2, m, true);

I must confess from the documentation that the "assembly" process and related options are not very clear.

Desktop (please complete the following information):

  • OS: macOS
  • Browser: observed on multiple browsers, Safari and Firefox
@fxcoudert fxcoudert added the bug label Feb 23, 2024
@dkoes
Copy link
Contributor

dkoes commented Feb 24, 2024

Are you sure the issue isn't with the data (ie, this is the right answer)? PyMol produces something similar.
image

@fxcoudert
Copy link
Author

Yes I am sure :)

This is what reference software for CIF files show. CrystalMaker:

Capture d’écran 2024-02-24 à 09 01 10

Mercury:

Capture d’écran 2024-02-24 à 09 01 20

When loading a CIF file, all atoms should be inside the unit cell.

@dkoes
Copy link
Contributor

dkoes commented Feb 24, 2024

This is exactly Issue #759. You need to pass an additional boolean argument to replicateUnitCell (prune) so atoms outside the unit cell aren't shown. I apologize for not updating the documentation (it is updated now).

@fxcoudert
Copy link
Author

fxcoudert commented Feb 24, 2024

@dkoes I apologise if I am being slow or dense, but I am not sure I understand the link with that issue. #759 is about atoms exactly at the boundary of the unit cell (if I read that correctly), which is not my case.

The CIF file used in the example code I put online is https://www.nanoporous.net/MOF_viewer/HKUST-1.cif

I tested the prune parameter. With replicateUnitCell(2, 2, 2, model, true, false) I still have the old behaviour:

Capture d’écran 2024-02-25 à 00 44 39

With replicateUnitCell(2, 2, 2, model, true, true) I have something even weirder:

Capture d’écran 2024-02-25 à 00 45 10

where the unit cell is not replicated, and still there are atoms outside the unit cell.

@fxcoudert
Copy link
Author

OK, I just understood that the issue is not with replicateUnitCell. Even if I don't replicate the unit cell, this line:

        let m = v.addModel(data, 'cif', {doAssembly: true, duplicateAssemblyAtoms: true, normalizeAssembly: true});

will give the rendering below:

Capture d’écran 2024-02-25 à 00 55 03

From the documentation, I believe normalizeAssembly should not let it do that?

dkoes added a commit that referenced this issue Mar 9, 2024
@dkoes
Copy link
Contributor

dkoes commented Mar 9, 2024

I see what is going on here. normalizeAssembly will adjust all the symmetry operations so that the center of the reference molecule remains in the unit cell after transformation. That is, it wraps the whole molecule as a unit. To get what I presume is your desired behavior it is necessary to wrap individual atoms. I've added this option (wrapAtoms) which must be specified with duplicateAssemblyAtoms since it wouldn't be possible to wrap atoms of the same image differently otherwise. I think this does what you want:
https://3dmol.org/tests/auto/generate_test.cgi?test=wrapatoms

@fxcoudert
Copy link
Author

Yeah, that works perfectly. Thanks!

@fxcoudert
Copy link
Author

Oh, I'm seeing what I think is a regression on another structure with symmetry.

Going to https://www.nanoporous.net/MOF_viewer/ and selecting MIL-101 in the dropbox:

Capture d’écran 2024-03-10 à 12 34 47

The CIF file is: https://www.nanoporous.net/MOF_viewer/MIL-101.cif
Two things are weird:

  • some atoms are outside the cell, despite wrapAtoms: true
  • there are many bonds from one side to another

dkoes added a commit that referenced this issue Mar 10, 2024
When wrapAtoms is set, also wrap the reference coordinates.  Change bond
connection behavior to only happen after wrapping if atoms are
duplicated and dontconnect isn't set.
@dkoes
Copy link
Contributor

dkoes commented Mar 10, 2024

The issue with that file is the reference coordinates are outside the box to start with. I've modified wrapAtoms to also wrap the reference coordinates (identity matrix symmetry). I've also changed the bond detection behavior to not determine bonds before wrapping.

@dkoes
Copy link
Contributor

dkoes commented Mar 10, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants