openff-interchange
openff-interchange copied to clipboard
User friendly way to get an array of charges
Description Please describe the behavior you would like added to Interchange.
Would it be possible to add a user-friendly property or method to get an ordered array of charges? Right now as far as I'm aware the only way to do so is below, and it's a bit of a mouthful. I think the charges are usually ordered by particle but the existence of #970 makes me want to be sure.
>>> charges = [
q for k, q in sorted(
interchange.collections["Electrostatics"].charges.items(),
key=lambda x: x[0].atom_indices
)
]
>>> charges
[<Quantity(-0.108680002, 'elementary_charge')>, <Quantity(0.0271700006, 'elementary_charge')>, <Quantity(0.0271700006, 'elementary_charge')>, <Quantity(0.0271700006, 'elementary_charge')>, <Quantity(0.0271700006, 'elementary_charge')>]
>>> charges_without_pint = [q.m for q in charges]
>>> charges_without_pint
[-0.10868000239133835, 0.027170000597834587, 0.027170000597834587, 0.027170000597834587, 0.027170000597834587]
(I know the ordering might be complicated for virtual sites.)