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

Issue with reading mol2 file and flattening the hierarchy #1206

Closed
CalCraven opened this issue Nov 13, 2024 · 2 comments
Closed

Issue with reading mol2 file and flattening the hierarchy #1206

CalCraven opened this issue Nov 13, 2024 · 2 comments

Comments

@CalCraven
Copy link
Contributor

Bug summary

Trying to fix an issue in GMSO with loading benzene molecules from different sources. The print_hierarchy method and children attribute seem to raise an error whenever they're accessed.

Code to reproduce the behavior

Please include a code snippet that can be used to reproduce this bug.

import mbuild as mb
from mbuild.utils.io import get_fn
cpd1 = mb.load(get_fn("benzene.mol2"))
cpd1.flatten(inplace=True)

cpd2 = mb.load("C1=CC=CC=C1", smiles=True)
cpd2.flatten(inplace=True)

cpd3 = mb.load("C1=CC=CC=C1", smiles=True)

for cpd in [cpd1, cpd2, cpd3]:
    compound_box = mb.packing.fill_box(compound=cpd, n_compounds=5, density=0.3)
    try:
        print(compound_box.print_hierarchy())
    except AttributeError as e:
        print(f"Error on {cpd} printing hierarchy")
        print("#"*10)
        print(e)

Output

Error on <Compound 12 particles, 12 bonds, non-periodic, id: 6948210192> printing hierarchy
##########
'NoneType' object has no attribute 'edges'
Compound, 60 particles, 60 bonds, 5 children
└── [Compound x 5], 12 particles, 12 bonds, 12 children
    ├── [C x 6], 1 particles, 3 bonds, 0 children
    └── [H x 6], 1 particles, 1 bonds, 0 children

Compound, 60 particles, 60 bonds, 5 children
└── [Compound x 5], 12 particles, 12 bonds, 12 children
    ├── [C x 6], 1 particles, 3 bonds, 0 children
    └── [H x 6], 1 particles, 1 bonds, 0 children

Software versions

  • Which version of mBuild are you using? (python -c "import mbuild as mb; print(mb.__version__)")
    1.0.0
  • Which version of Python (python --version)?
    3.11
  • Which operating system?
    MACOSX
@CalCraven CalCraven changed the title Issue with reading mol Issue with reading mol2 file and flattening the hierarchy Nov 13, 2024
@CalCraven
Copy link
Contributor Author

x = compound_box.children[0].children
for particle in cpd1.particles():
    print(particle.root.bond_graph)

compound_box = mb.packing.fill_box(compound=cpd1, n_compounds=5, density=0.3)
for particle in compound_box.particles():
    print(particle.root.bond_graph)

Outputs

BondGraph with 12 nodes and 12 edges
BondGraph with 12 nodes and 12 edges
BondGraph with 12 nodes and 12 edges
BondGraph with 12 nodes and 12 edges
BondGraph with 12 nodes and 12 edges
BondGraph with 12 nodes and 12 edges
BondGraph with 12 nodes and 12 edges
BondGraph with 12 nodes and 12 edges
BondGraph with 12 nodes and 12 edges
BondGraph with 12 nodes and 12 edges
BondGraph with 12 nodes and 12 edges
BondGraph with 12 nodes and 12 edges
None
None
None
None
None
None
None
None
None
None
BondGraph with 60 nodes and 60 edges
None
None
None
None
None
None
None
None
None
None
None
BondGraph with 60 nodes and 60 edges
None
None
None
None
None
None
None
None
None
None
None
BondGraph with 60 nodes and 60 edges
None
None
None
None
None
None
None
None
None
None
None
BondGraph with 60 nodes and 60 edges
None
None
None
None
None
None
None
None
None
None
None
BondGraph with 60 nodes and 60 edges
None

So it's something to do with the fill_box not setting the root correctly

@chrisjonesBSU
Copy link
Contributor

Fixed by #1208

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants