# Path: molmod/units.py
# def parse_unit(expression):
# 
# Path: molmod/transformations.py
# def fit_rmsd(ras, rbs, weights=None):
#     """Fit geometry rbs onto ras, returns more info than superpose
# 
#        Arguments:
#         | ``ras``  --  a numpy array with 3D coordinates of geometry A,
#                        shape=(N,3)
#         | ``rbs``  --  a numpy array with 3D coordinates of geometry B,
#                        shape=(N,3)
# 
#        Optional arguments:
#         | ``weights``  --  a numpy array with fitting weights for each
#                            coordinate, shape=(N,)
# 
#        Return values:
#         | ``transformation``  --  the transformation that brings geometry A into
#                                   overlap with geometry B
#         | ``rbs_trans``  --  the transformed coordinates of geometry B
#         | ``rmsd``  --  the rmsd of the distances between corresponding atoms in
#                         geometry A and B
# 
#        This is a utility routine based on the function superpose. It just
#        computes rbs_trans and rmsd after calling superpose with the same
#        arguments
#     """
#     transformation = superpose(ras, rbs, weights)
#     rbs_trans = transformation * rbs
#     rmsd = compute_rmsd(ras, rbs_trans)
#     return transformation, rbs_trans, rmsd


from molmod.units import angstrom
from molmod.transformations import fit_rmsd
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>
#
# --
"""Tools to analyze the symmetry of molecules"""




__all__ = ["compute_rotsym"]


def compute_rotsym(molecule, graph, threshold=1e-3*angstrom):
    """Compute the rotational symmetry number

       Arguments:
        | ``molecule``  --  The molecule
        | ``graph``  --  The corresponding bond graph

       Optional argument:
        | ``threshold``  --  only when a rotation results in an rmsd below the
                             given threshold, the rotation is considered to
                             transform the molecule onto itself.
    """
    result = 0
    for match in graph.symmetries:
        permutation = list(j for i,j in sorted(match.forward.items()))
        new_coordinates = molecule.coordinates[permutation]

# Path: molmod/units.py
# def parse_unit(expression):
# 
# Path: molmod/transformations.py
# def fit_rmsd(ras, rbs, weights=None):
#     """Fit geometry rbs onto ras, returns more info than superpose
# 
#        Arguments:
#         | ``ras``  --  a numpy array with 3D coordinates of geometry A,
#                        shape=(N,3)
#         | ``rbs``  --  a numpy array with 3D coordinates of geometry B,
#                        shape=(N,3)
# 
#        Optional arguments:
#         | ``weights``  --  a numpy array with fitting weights for each
#                            coordinate, shape=(N,)
# 
#        Return values:
#         | ``transformation``  --  the transformation that brings geometry A into
#                                   overlap with geometry B
#         | ``rbs_trans``  --  the transformed coordinates of geometry B
#         | ``rmsd``  --  the rmsd of the distances between corresponding atoms in
#                         geometry A and B
# 
#        This is a utility routine based on the function superpose. It just
#        computes rbs_trans and rmsd after calling superpose with the same
#        arguments
#     """
#     transformation = superpose(ras, rbs, weights)
#     rbs_trans = transformation * rbs
#     rmsd = compute_rmsd(ras, rbs_trans)
#     return transformation, rbs_trans, rmsd


# Path: molmod/symmetry.py
from molmod.units import angstrom
from molmod.transformations import fit_rmsd

# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>
#
# --
"""Tools to analyze the symmetry of molecules"""




__all__ = ["compute_rotsym"]


def compute_rotsym(molecule, graph, threshold=1e-3*angstrom):
    """Compute the rotational symmetry number

       Arguments:
        | ``molecule``  --  The molecule
        | ``graph``  --  The corresponding bond graph

       Optional argument:
        | ``threshold``  --  only when a rotation results in an rmsd below the
                             given threshold, the rotation is considered to
                             transform the molecule onto itself.
    """
    result = 0
    for match in graph.symmetries:
        permutation = list(j for i,j in sorted(match.forward.items()))
        new_coordinates = molecule.coordinates[permutation]

        rmsd = fit_rmsd(molecule.coordinates, new_coordinates)[2]