Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion rmgpy/species.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,17 @@ def from_adjacency_list(self, adjlist, raise_atomtype_exception=True, raise_char
list in the `molecule` attribute. Does not generate resonance isomers
of the loaded molecule.
"""
lines = adjlist.splitlines()

if len(lines[0].split()) == 1:
label = lines.pop(0) # remove the first line if it is a label before detecting cutting label
adjlist_no_label = '\n'.join(lines)
else:
adjlist_no_label = adjlist

# detect if it contains cutting label
_ , cutting_label_list = Fragment().detect_cutting_label(adjlist)
_ , cutting_label_list = Fragment().detect_cutting_label(adjlist_no_label)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

detect_cutting_label is designed to work on SMILES-like strings, and looks quite complex.
what does a cutting label in an adjacency list look like? there might be a much faster way to just see if it's present in the adjacency list (which seems to be all you need to know here?)

@lily90502 lily90502 Aug 4, 2023

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An example of fragment RCC adjacency list:
1 C u0 p0 c0 {2,S} {3,S} {4,S} {5,S} 2 C u0 p0 c0 {1,S} {6,S} {7,S} {8,S} 3 R u0 p0 c0 {1,S} 4 H u0 p0 c0 {1,S} 5 H u0 p0 c0 {1,S} 6 H u0 p0 c0 {2,S} 7 H u0 p0 c0 {2,S} 8 H u0 p0 c0 {2,S}

I think another way is to check the atom type to see if it is Atom or Cuttinglabel. But I guess this will be slower?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, there are definitely better ways to do this. I'm not familiar with the detect_cutting_label function, so this PR is a quick fix, but someone should work on improving detect_cutting_label to specialize in adjacency list.


if cutting_label_list == []:
self.molecule = [Molecule().from_adjacency_list(adjlist, saturate_h=False,
raise_atomtype_exception=raise_atomtype_exception,
Expand Down