QuantumATK Forum

QuantumATK => General Questions and Answers => Topic started by: AsifShah on October 30, 2022, 07:40

Title: Hook Method for Partial Charge
Post by: AsifShah on October 30, 2022, 07:40
Dear Admin,

I am trying to call partial charges on configuration inside a hook method as:

def post_step_hook(step, time, configuration, forces, stress):
    PC=PartialCharges(configuration)

md_trajectory = MolecularDynamics(
    bulk_configuration,
    constraints=constraints,
    trajectory_filename='File1.hdf5',
    steps=3000,
    log_interval=10,
    post_step_hook=post_step_hook,
    method=method
)


But I get the following error:
Traceback (most recent call last):
  File "Electric_Field_F_Migration.py", line 923, in <module>
    md_trajectory = MolecularDynamics(
  File "zipdir/NL/Dynamics/MolecularDynamics/MolecularDynamics.py", line 776, in MolecularDynamics
  File "zipdir/NL/Dynamics/MolecularDynamics/HookFunctionContainer.py", line 252, in callAllHookFunctions
  File "Electric_Field_F_Migration.py", line 914, in post_step_hook
    PC=PartialCharges(configuration)
  File "zipdir/NL/Analysis/PartialCharges.py", line 85, in __init__
  File "zipdir/NL/Analysis/Analysis.py", line 282, in __init__
  File "zipdir/NL/Analysis/Analysis.py", line 253, in _supportConfigurationWithCalculator
  File "zipdir/NL/Analysis/Analysis.py", line 209, in _supportConfiguration
  File "zipdir/NL/Analysis/AnalysisUtilities.py", line 176, in checkConfiguration
NL.ComputerScienceUtilities.Exceptions.NLTypeError: The parameter 'configuration' must be an instance of one of the following: BulkConfiguration, MoleculeConfiguration, DeviceConfiguration


Kindly help in this case, as how to calculate partialcharges inside hook?
Title: Re: Hook Method for Partial Charge
Post by: Anders Blom on November 8, 2022, 08:11
What do you get if you include
print(configuration)
nlprint(configuration)
in the hook function? That will give us a better clue. Or attach your script so we can test it
Title: Re: Hook Method for Partial Charge
Post by: AsifShah on November 9, 2022, 07:16
I have attached the script below.
Title: Re: Hook Method for Partial Charge
Post by: Anders Blom on November 9, 2022, 19:42
Turns out the correct way to do it is to use

PC = configuration.partialCharges()
Title: Re: Hook Method for Partial Charge
Post by: AsifShah on November 10, 2022, 12:41
I already tried this one but it returns nothing.
Title: Re: Hook Method for Partial Charge
Post by: Anders Blom on November 10, 2022, 20:02
Yes, it seems the correct way is

pc = PartialCharges(configuration.configuration())

Previous reply only works if partial charges are already computed and you want to extract them, which of course is not your case.
Title: Re: Hook Method for Partial Charge
Post by: AsifShah on November 12, 2022, 09:49
Thanks yes it did work.