SEDenmarkLab / molli

Molecular Library Toolbox
https://molli.readthedocs.io
MIT License
21 stars 1 forks source link

mol.del_atom(a) does not remove corresponding charges from mol.atomic_charges #28

Closed caseyolen closed 9 months ago

caseyolen commented 1 year ago
            print(len(mol._atoms))
            print(len(mol.bonds))
            print(len(mol.atomic_charges))
            bromines = [i for i in mol.yield_atoms_by_element('Br')]
            print(bromines)
            assert len(bromines) == 2
            carbon = next(mol.connected_atoms(bromines[0]))

            for a in bromines:
                mol.del_atom(a)
            mol.del_atom(carbon)      

            print(len(mol._atoms))
            print(len(mol.bonds))
            print(len(mol.atomic_charges)) ```python


Out:
92
99
92
[Atom(element=Br, isotope=None, label='BR'), Atom(element=Br, isotope=None, label='BR')]
89
95
92
caseyolen commented 1 year ago

Override del_atom in molecule class to fix the problem:

def del_atom(self, _a: AtomLike):
        ai = self.index_atom(_a)
        self._atomic_charges = np.delete(self._atomic_charges, ai, 0)
        super().del_atom(_a)
esalx commented 1 year ago

Should be fixed in an upcoming PR. Stay tuned!