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

After using RemoveScatterer, the catalogue of athoms doesn't update #41

Closed
ji-ze opened this issue Jul 15, 2024 · 13 comments
Closed

After using RemoveScatterer, the catalogue of athoms doesn't update #41

ji-ze opened this issue Jul 15, 2024 · 13 comments
Assignees
Labels

Comments

@ji-ze
Copy link

ji-ze commented Jul 15, 2024

Hello,
I generate a primitive lattice with random carbon atoms. If I remove an atom by RemoveScatterer(), the function GetFormula writes the original formula before removing an atom. If I use GetNbScatterer, I get a correct answer. It isn't practical, because I want to generate an electron density map, but I get the same result (before/after). I'm including my code.
Thanks for answers.

from pyobjcryst.crystal import *

# some lines

c = Crystal(5, 5, 5, pi/2, pi/2, pi/2, "P1")

# some lines

i = nbAtoms
at = list()
carbon = ScatteringPowerAtom("C", "C")
c.AddScatteringPower(carbon)
while i > 0:
    # position = [random(), random(), random()]
    at.append(Atom(random(), random(), random(), f"C{i}", carbon, 1.0))
    c.AddScatterer(at[nbAtoms-i])
    import numpy as np

    darr = np.array(c.GetMinDistanceTable(0.0))
    minimum = darr.min()
    print(minimum)
    if minimum < min_distance:
        c.RemoveScatterer(at[nbAtoms-i])
        del(at[nbAtoms-i])
        i += 1
    i -= 1

formula = c.GetFormula()
print("Molecular formula:", formula)

c.RemoveScatterer(at[0])

formula = c.GetFormula()
print("Molecular formula:", formula)

image
(Output after removing 2 atoms. The 1st line is GetNbScatterer and 2nd is GetFormula)

@vincefn vincefn self-assigned this Jul 15, 2024
@vincefn vincefn added the bug label Jul 15, 2024
@vincefn
Copy link
Collaborator

vincefn commented Jul 15, 2024

Thanks for the report.

For some reason, the ScatteringComponentList is not updated after removing the Scatterer, which leads to the non-updated formula.

As a temporary workaround, you can add a very small value to any scatterer coordinate, and it will force the update of the ScatteringComponentList.

For example, add a single line:
c.GetScatterer(0).X += 0.0001

@ji-ze
Copy link
Author

ji-ze commented Aug 6, 2024

Thank you for getting back to me. It works.

@ji-ze ji-ze closed this as completed Aug 13, 2024
@sbillinge
Copy link
Contributor

@sbillinge reopening. I don't think this is fixed, just a workaround reported.

@sbillinge sbillinge reopened this Aug 13, 2024
@vincefn
Copy link
Collaborator

vincefn commented Aug 19, 2024

Yes, it's still on the todo list, but this needs to be done & tested first upstream in https://github.com/vincefn/objcryst, and then propagated to libobjcryst...

I need first to merge two objcryst branches, and only then I can have a look at this. Hopefully next week before EPDIC.

@sbillinge
Copy link
Contributor

@vincefn looking forward to seeing you at EPDIC....

@vincefn
Copy link
Collaborator

vincefn commented Aug 19, 2024

Sorry, won't be there, but Jan Rohlicek will be presenting some new Fox features (new grid/distributed computed version, and inter-molecular constraints for combination with NRM)

@sbillinge
Copy link
Contributor

aw, too bad.

@vincefn
Copy link
Collaborator

vincefn commented Sep 7, 2024

This should be fixed in libobjcryst 2024.2 - hopefully it'll be available in conda-forge tomorrow

@sbillinge
Copy link
Contributor

@ji-ze please let us know if 2024-2 fixes this problem for you and we can close this issue.

@vincefn
Copy link
Collaborator

vincefn commented Sep 10, 2024

@ji-ze libobjcryst=2024.2.1 finally went through on conda-forge, but the pyobjcryst conda package now needs to be updated. Probably two more days unless you install from source.

@vincefn
Copy link
Collaborator

vincefn commented Sep 10, 2024

I spoke too quickly - the libobjcryst built packages are missing the headers... I'll mark those as broken, sorry...

@vincefn
Copy link
Collaborator

vincefn commented Sep 10, 2024

build _1 of libobjcryst 2024.2.1 should be OK now - build 0 should soon be marked as broken.

@vincefn
Copy link
Collaborator

vincefn commented Sep 13, 2024

pyobjcryst 2024.2 is out on conda, so this should be working without needing to compile from source. Re-open if you still have issues.

@vincefn vincefn closed this as completed Sep 13, 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

3 participants