31
31
#include " SireMaths/align.h"
32
32
33
33
#include " SireMol/core.h"
34
+ #include " SireMol/moleditor.h"
34
35
35
36
#include " SireStream/datastream.h"
36
37
#include " SireStream/shareddatastream.h"
@@ -723,20 +724,40 @@ AtomMapping AtomMapping::alignTo0() const
723
724
QVector<Vector> coords0 = this ->atms0 .property <Vector>(map0[" coordinates" ]).toVector ();
724
725
QVector<Vector> coords1 = this ->atms1 .property <Vector>(map1[" coordinates" ]).toVector ();
725
726
726
- // calculate the transform to do a RMSD aligment of the two sets of coordinates
727
- auto transform = SireMaths::getAlignment (coords0, coords1, true );
728
-
729
- auto mols1 = this ->orig_atms1 .molecules ();
730
-
731
727
AtomMapping ret (*this );
732
728
733
- for ( int i = 0 ; i < mols1 .count (); ++i )
729
+ if (( this -> count () == 1 ) and ((coords0. count () == 1 ) or (coords1 .count () == 1 )) )
734
730
{
735
- auto mol = mols1[i].move ().transform (transform, map1).commit ();
731
+ // if we've only mapped a single atom and one molecule is a monatomic ion,
732
+ // then simply replace the coordinates of the mapped atom.
733
+
734
+ auto atom0 = this ->atms0 [0 ];
735
+ auto atom1 = this ->atms1 [0 ];
736
+
737
+ auto mol = this ->orig_atms1 .molecules ()[0 ];
738
+
739
+ mol = mol.edit ().atom (atom1.index ())
740
+ .setProperty (map1[" coordinates" ].source (), coords0[0 ])
741
+ .molecule ().commit ();
736
742
737
743
ret.atms1 .update (mol);
738
744
ret.orig_atms1 .update (mol);
739
745
}
746
+ else
747
+ {
748
+ // calculate the transform to do a RMSD aligment of the two sets of coordinates
749
+ auto transform = SireMaths::getAlignment (coords0, coords1, true );
750
+
751
+ auto mols1 = this ->orig_atms1 .molecules ();
752
+
753
+ for (int i = 0 ; i < mols1.count (); ++i)
754
+ {
755
+ auto mol = mols1[i].move ().transform (transform, map1).commit ();
756
+
757
+ ret.atms1 .update (mol);
758
+ ret.orig_atms1 .update (mol);
759
+ }
760
+ }
740
761
741
762
return ret;
742
763
}
@@ -754,20 +775,40 @@ AtomMapping AtomMapping::alignTo1() const
754
775
QVector<Vector> coords0 = this ->atms0 .property <Vector>(map0[" coordinates" ]).toVector ();
755
776
QVector<Vector> coords1 = this ->atms1 .property <Vector>(map1[" coordinates" ]).toVector ();
756
777
757
- // calculate the transform to do a RMSD aligment of the two sets of coordinates
758
- auto transform = SireMaths::getAlignment (coords1, coords0, true );
759
-
760
- auto mols0 = this ->orig_atms0 .molecules ();
761
-
762
778
AtomMapping ret (*this );
763
779
764
- for ( int i = 0 ; i < mols0 .count (); ++i )
780
+ if (( this -> count () == 1 ) and ((coords0. count () == 1 ) or (coords1 .count () == 1 )) )
765
781
{
766
- auto mol = mols0[i].move ().transform (transform, map0).commit ();
782
+ // if we've only mapped a single atom and one molecule is a monatomic ion,
783
+ // then simply replace the coordinates of the mapped atom.
784
+
785
+ auto atom0 = this ->atms0 [0 ];
786
+ auto atom1 = this ->atms1 [0 ];
787
+
788
+ auto mol = this ->orig_atms0 .molecules ()[0 ];
789
+
790
+ mol = mol.edit ().atom (atom0.index ())
791
+ .setProperty (map0[" coordinates" ].source (), coords0[0 ])
792
+ .molecule ().commit ();
767
793
768
794
ret.atms0 .update (mol);
769
795
ret.orig_atms0 .update (mol);
770
796
}
797
+ else
798
+ {
799
+ // calculate the transform to do a RMSD aligment of the two sets of coordinates
800
+ auto transform = SireMaths::getAlignment (coords1, coords0, true );
801
+
802
+ auto mols0 = this ->orig_atms0 .molecules ();
803
+
804
+ for (int i = 0 ; i < mols0.count (); ++i)
805
+ {
806
+ auto mol = mols0[i].move ().transform (transform, map0).commit ();
807
+
808
+ ret.atms0 .update (mol);
809
+ ret.orig_atms0 .update (mol);
810
+ }
811
+ }
771
812
772
813
return ret;
773
814
}
0 commit comments