tzok / rnapolis-py

A Python library containing RNA-related bioinformatics functions and classes.
MIT License
12 stars 3 forks source link

"math domain error" during annotator run #205

Closed DiegoBarMor closed 1 month ago

DiegoBarMor commented 5 months ago

Hello, I was running the annotator for the 488D structure from the PDB, and stumbled across this error:

/path.../rnapolis/annotator.py:59: RuntimeWarning: invalid value encountered in scalar divide
  return math.acos(numpy.dot(v1, v2) / numpy.linalg.norm(v1) / numpy.linalg.norm(v2))
Traceback (most recent call last):
  File "/path.../rnapolis/annotator.py", line 645, in <module>
    main()
  File "/path.../rnapolis/annotator.py", line 619, in main
    structure2d, dot_brackets = extract_secondary_structure(
  File "/path.../rnapolis/annotator.py", line 491, in extract_secondary_structure
    base_interactions = extract_base_interactions(tertiary_structure, model)
  File "/path.../rnapolis/annotator.py", line 481, in extract_base_interactions
    stackings = find_stackings(tertiary_structure, model)
  File "/path.../rnapolis/annotator.py", line 440, in find_stackings
    angle_between_vectors(normal_i, normal_j),
  File "/path.../rnapolis/annotator.py", line 59, in angle_between_vectors
    return math.acos(numpy.dot(v1, v2) / numpy.linalg.norm(v1) / numpy.linalg.norm(v2))
ValueError: math domain error

The problem seems to be on the following lines from find_stackings:

    for i, j in kdtree.query_pairs(STACKING_MAX_DISTANCE):
        residue_i = coordinates_residue_map[coordinates[i]]
        residue_j = coordinates_residue_map[coordinates[j]]

        # check angle between normals
        normal_i = residue_i.base_normal_vector
        normal_j = residue_j.base_normal_vector

where for some reason, in one iteration both residue_i and residue_j take the value D.A151. Attached the input file.

488D.pdb.txt

tzok commented 5 months ago

@DiegoBarMor The issue is that B.A151 and D.A151 share identical coordinates, with one having an occupancy of 0.4 and the other 0.6.

Currently, RNApolis doesn't account for occupancy, and it's challenging to integrate this into a tool like annotator. I plan to add a filter to retain only the residue with higher occupancy in such overlap cases.

tzok commented 5 months ago

Thank you for reporting this issue. I'll keep it open, but I can't specify when the filter will be implemented. In the meantime, please manually remove overlaps in the provided file. Apologies for any inconvenience.

tzok commented 1 month ago

@DiegoBarMor Please retry with RNApolis 0.4.6, and this bug you have submitted should no longer be present. Thank you again for reporting and for your patience!