Skip to content

Commit

Permalink
Small Bug Fix and Minor Improvements
Browse files Browse the repository at this point in the history
Bug fixed for finding missing atoms.
Bug is not likely to have caused problems.
Only likely to affect reactions where lots of atoms were moving around.
Now prints a message once tasks are finished
Inline documentation improved.
  • Loading branch information
Matt Bone committed Aug 31, 2021
1 parent 34d93ba commit e2f9fe5
Show file tree
Hide file tree
Showing 28 changed files with 1,688 additions and 1,665 deletions.
21 changes: 20 additions & 1 deletion AtomObjectBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,31 @@ def check_mapped(self, mappedIDs, searchIndex, elementDict):


def map_elements(self, atomObject, preAtomObjectDict, postAtomObjectDict):
"""Map preAtom IDs to postAtomIDs by comparing neighbouring element symbols.
Compares the occurence of string chemical element symbols of a preAtom's neighbours
to the known postAtom's neighbours. Creates a list of new mappedIDs and any missing IDs
based on the neighbours of the known pre and postAtom pair.
Relies on compare_symmetric atoms to handle non-H atoms with >1 occurence.
Args:
self: This is a preAtom that has succesfully been mapped
atomObject: The known postAtom that has already been mapped to the preAtom
preAtomObjectDict: A dictionary of all preAtoms in the molecule
postAtomObjectDict: A dictionary of all the postAtoms in the molecule
Returns:
A partial mappedIDlist, partial missing pre and postAtom lists and additional atoms for the queue
"""

# Output variables
mapList = []
missingPreAtoms = []
queueAtoms = []

def allowed_maps(preAtom, postAtom):
'''Populate missing atoms prematurely instead of making misleading
maps based on element occurence'''
# Checks if elements appear the same number of times in pre and post atoms
# If they don't, mapping is not allowed to take place and atoms are moved to missing lists
preElementOccurences = Counter(preAtom.mappedNeighbourElements)
Expand Down Expand Up @@ -205,7 +224,7 @@ def matchNeighbour(preAtom, postAtom, preAtomIndex, postAtomIndex, mapList, queu
postAtom.mappedNeighbourIDs.pop(postAtomIndex)
postAtom.mappedNeighbourElements.pop(postAtomIndex)

# Loop through neighbours for atom in one state and compare to neighbours of atom in other state
# Loop through neighbours for preAtom and compare to neighbours of postAtom
for preIndex, neighbour in enumerate(self.mappedNeighbourElements):
elementOccurence = atomObject.mappedNeighbourElements.count(neighbour)

Expand Down
2 changes: 2 additions & 0 deletions AutoMapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,5 @@
elif tool == 'map':
map_processor(directory, args.data_files[0], args.data_files[1], args.save_name[0], args.save_name[1], args.ba[:2], args.ba[2:], args.da, args.ebt, args.debug)

# Print message to show AutoMapper is complete
print('AutoMapper Task Complete')
4 changes: 3 additions & 1 deletion MapProcessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def map_processor(directory, preDataFileName, postDataFileName, preMoleculeFileN
prePartialAtomsSet = keep_all_neighbours(preAtomObjectDict, preBondingAtoms, prePartialAtomsSet)
postPartialAtomsSet = keep_all_neighbours(postAtomObjectDict, postBondingAtoms, postPartialAtomsSet)

# Keep delete atoms - IMPROVEMENT: Need to detect byproducts that are not deleted
# Keep delete atoms
if preDeleteAtoms is not None:
prePartialAtomsSet.update(preDeleteAtoms)
postPartialAtomsSet.update(postDeleteAtoms)
Expand All @@ -91,6 +91,8 @@ def map_processor(directory, preDataFileName, postDataFileName, preMoleculeFileN

# Check the edges aren't too close to atoms that change type
preExtendEdgeDict = verify_edge_atoms(preEdgeAtoms, mappedIDList, preAtomObjectDict, postAtomObjectDict)

# Update mapped list and partial atom sets if edge atoms need extending
mappedIDList, prePartialAtomsSet, postPartialAtomsSet = extend_edge_atoms(preExtendEdgeDict, mappedIDList, preAtomObjectDict, postAtomObjectDict, prePartialAtomsSet, postPartialAtomsSet)

# Refind edge atoms after potential extension
Expand Down
6 changes: 3 additions & 3 deletions PathSearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def map_missing_atoms(missingPreAtomObjects, missingPostAtomObjects, mappedIDLis
elementOccurence = missingPostAtomElements.count(preAtom.element)

if elementOccurence == 0:
print(f"Couldn't find a match in post missing atom for {preAtom.atomID}")
print(f"Error: Couldn't find a match in post missing atom for {preAtom.atomID}. Please try again or map the atom manually.")

elif elementOccurence == 1:
postIndex = missingPostAtomElements.index(preAtom.element)
Expand Down Expand Up @@ -171,8 +171,8 @@ def map_from_path(directory, preFileName, postFileName, elementsByType, debug, p
# Enable inference if no new missing atoms were solved this loop
if missingPreAtomCount == len(missingPreAtomList):
inference = True
else:
infernce = False
else: # Disable inference if missing atoms were solved as other atoms may now be found without inference
inference = False

timeoutCounter += 1

Expand Down
2 changes: 1 addition & 1 deletion Test_Cases/Map_Tests/Caprolactam/automap.data
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ BondingIDs

EdgeIDs

12
9
12

Equivalences

Expand Down
Loading

0 comments on commit e2f9fe5

Please sign in to comment.