@@ -597,8 +597,71 @@ namespace SireRDKit
597
597
RDKit::RWMol molecule;
598
598
molecule.beginBatchEdit ();
599
599
600
+ // set the name of the molecule
600
601
molecule.setProp <std::string>(" _Name" , mol.name ().value ().toStdString ());
601
602
603
+ // set any SDF tags as properties
604
+ std::string sdf_tag;
605
+ if (mol.hasProperty (" sdf_data" ))
606
+ {
607
+ const auto sdf_data = mol.property (" sdf_data" ).asA <SireBase::Properties>();
608
+
609
+ for (const auto &tag : sdf_data.propertyKeys ())
610
+ {
611
+ try
612
+ {
613
+ molecule.setProp <std::string>(tag.toStdString (), sdf_data.property (tag).asAString ().toStdString ());
614
+ }
615
+ catch (...)
616
+ {
617
+ const auto string_array = sdf_data.property (tag).asA <SireBase::StringArrayProperty>();
618
+
619
+ QString string;
620
+ for (int i=0 ; i<string_array.size (); i++)
621
+ {
622
+ string.append (string_array[i]);
623
+ if (i < string_array.size () - 1 )
624
+ {
625
+ string.append (" \n " );
626
+ }
627
+ }
628
+
629
+ molecule.setProp <std::string>(tag.toStdString (), string.toStdString ());
630
+ }
631
+ }
632
+ }
633
+
634
+ // set and existing RDKit data as properties
635
+ std::string rdkit_tag;
636
+ if (mol.hasProperty (" rdkit_data" ))
637
+ {
638
+ const auto rdkit_data = mol.property (" rdkit_data" ).asA <SireBase::Properties>();
639
+
640
+ for (const auto &tag : rdkit_data.propertyKeys ())
641
+ {
642
+ try
643
+ {
644
+ molecule.setProp <std::string>(tag.toStdString (), rdkit_data.property (tag).asAString ().toStdString ());
645
+ }
646
+ catch (...)
647
+ {
648
+ const auto string_array = rdkit_data.property (tag).asA <SireBase::StringArrayProperty>();
649
+
650
+ QString string;
651
+ for (int i=0 ; i<string_array.size (); i++)
652
+ {
653
+ string.append (string_array[i]);
654
+ if (i < string_array.size () - 1 )
655
+ {
656
+ string.append (" \n " );
657
+ }
658
+ }
659
+
660
+ molecule.setProp <std::string>(tag.toStdString (), string.toStdString ());
661
+ }
662
+ }
663
+ }
664
+
602
665
const auto atoms = mol.atoms ();
603
666
604
667
QList<SireMol::Element> elements;
@@ -793,7 +856,6 @@ namespace SireRDKit
793
856
try
794
857
{
795
858
RDKit::MolOps::sanitizeMol (molecule);
796
-
797
859
}
798
860
catch (...)
799
861
{
@@ -997,6 +1059,37 @@ namespace SireRDKit
997
1059
}
998
1060
}
999
1061
1062
+ // copy additional properties from the molecule
1063
+ SireBase::Properties props;
1064
+
1065
+ for (const auto &prop : mol->getPropList ())
1066
+ {
1067
+ const auto sire_prop = QString::fromStdString (prop);
1068
+
1069
+ // skip internal properties
1070
+ if (sire_prop.startsWith (" _" ))
1071
+ continue ;
1072
+
1073
+ const auto value = QString::fromStdString (mol->getProp <std::string>(prop));
1074
+ const auto list = value.split (" \n " );
1075
+
1076
+ // there is a list of values
1077
+ if (list.count () > 1 )
1078
+ {
1079
+ props.setProperty (sire_prop, SireBase::wrap (list));
1080
+ }
1081
+ // there is a single value
1082
+ else
1083
+ {
1084
+ props.setProperty (sire_prop, SireBase::wrap (value));
1085
+ }
1086
+ }
1087
+
1088
+ if (not props.isEmpty ())
1089
+ {
1090
+ molecule.setProperty (" rdkit_data" , props);
1091
+ }
1092
+
1000
1093
return molecule.commit ();
1001
1094
}
1002
1095
0 commit comments