mbuild icon indicating copy to clipboard operation
mbuild copied to clipboard

Loss of meaningful port names and labels

Open jaclark5 opened this issue 11 months ago • 0 comments

Bug summary

Expect that upon flattening a Compound the labels will remain meaningful, and after removing atoms, labels will remain in order.

Code to reproduce the behavior

from mbuild.lib.moieties.peg import PegMonomer
from mbuild.lib.recipes.polymer import Polymer

Mon = PegMonomer()
print("Before", Mon.labels.keys())

Molecule = Polymer(monomers=Mon)
Molecule.build(1, add_hydrogens=True)
Molecule.flatten(inplace=True)
print("After Flatten", list(Molecule.labels.keys()))

# Remove Hydrogen Atoms
remove_array = []
for child in Molecule.children:
    if child.name == "H":
        remove_array.append(child)
Molecule.remove(remove_array)
print(list(Molecule.labels.keys()))
Before ['C', 'C[0]', 'H', 'H[0]', 'H[1]', 'C[1]', 'H[2]', 'H[3]', 'O', 'O[0]', 'down', 'up']
After Flatten ['monomer', 'H', 'Compound', 'Compound[0]', 'Compound[1]', 'Compound[2]', 'Compound[3]', 'Compound[4]', 'Compound[5]', 'Compound[6]', 'Compound[7]', 'Compound[8]']
After Remove H ['monomer', 'H', 'Compound', 'Compound[0]', 'Compound[3]', 'Compound[6]', 'port', 'port[1]', 'port[3]', 'port[5]', 'port[7]', 'port[9]', 'port[11]']

Software versions

  • Which version of mBuild are you using? 0.17.0
  • Which version of Python (python --version)? 3.8.15
  • Which operating system? MacOS 14.3.1

jaclark5 avatar Mar 10 '24 03:03 jaclark5