Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
greglandrum authored Nov 21, 2024
1 parent 614116a commit a0a21e6
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
9 changes: 7 additions & 2 deletions Code/GraphMol/FileParsers/MolFileWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,9 +546,10 @@ bool hasNonDefaultValence(const Atom *atom) {
SmilesWrite ::inOrganicSubset(atom->getAtomicNum())) {
// for the ones we "know", we may have to specify the valence if it's
// not the default value
auto effAtomicNum = atom->getAtomicNum() - atom->getFormalCharge();
return atom->getNoImplicit() &&
(atom->getExplicitValence() !=
PeriodicTable::getTable()->getDefaultValence(atom->getAtomicNum()));
PeriodicTable::getTable()->getDefaultValence(effAtomicNum));
}
return true;
}
Expand Down Expand Up @@ -1225,7 +1226,11 @@ std::string getV3000CTAB(const ROMol &tmol,
return res;
}
} // namespace FileParserUtils
enum class MolFileFormat { V2000, V3000, unspecified };
enum class MolFileFormat {
V2000,
V3000,
unspecified
};

//------------------------------------------------
//
Expand Down
27 changes: 26 additions & 1 deletion Code/GraphMol/FileParsers/file_parsers_catch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7155,7 +7155,7 @@ class FragTest {
expectedResult(expectedResultInit),
reapplyMolBlockWedging(reapplyMolBlockWedgingInit),
origSgroupCount(origSgroupCountInit),
newSgroupCount(newSgroupCountInit){};
newSgroupCount(newSgroupCountInit) {};
};

void testFragmentation(const FragTest &fragTest) {
Expand Down Expand Up @@ -7412,3 +7412,28 @@ TEST_CASE("Github #7306: bad crossed bonds in large aromatic rings") {
CHECK(ctab.find("2 3\n") == std::string::npos);
}
}

TEST_CASE(
"Github #8023: explicit valence for charged organic atoms in mol block") {
SECTION("as reported 1") {
auto m = "C[NH3+]"_smiles;
REQUIRE(m);
auto ctab = MolToMolBlock(*m);
CHECK(ctab.find("N 0 0 0 0 0 0 0") != std::string::npos);
ctab = MolToV3KMolBlock(*m);
CHECK(ctab.find("CHG=1") != std::string::npos);
CHECK(ctab.find("VAL=4") == std::string::npos);
}
SECTION("nitro-type") {
auto m = "C[N+](=S)[O-]"_smiles;
REQUIRE(m);
auto ctab = MolToMolBlock(*m);
CHECK(ctab.find("N 0 0 0 0 0 0 0") != std::string::npos);
CHECK(ctab.find("O 0 0 0 0 0 0 0") != std::string::npos);
ctab = MolToV3KMolBlock(*m);
CHECK(ctab.find("CHG=1") != std::string::npos);
CHECK(ctab.find("VAL=4") == std::string::npos);
CHECK(ctab.find("CHG=-1") != std::string::npos);
CHECK(ctab.find("VAL=1") == std::string::npos);
}
}
10 changes: 5 additions & 5 deletions Code/GraphMol/MarvinParse/test_data/Na_Mg_Al_OH.expected.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
M V30 BEGIN CTAB
M V30 COUNTS 12 3 0 0 0
M V30 BEGIN ATOM
M V30 1 O 0.000000 1.750000 0.000000 0 CHG=-1 VAL=1
M V30 2 O 2.299038 0.000000 0.000000 0 CHG=-1 VAL=1
M V30 3 O 0.000000 2.750000 0.000000 0 CHG=-1 VAL=1
M V30 4 O 3.299038 0.000000 0.000000 0 CHG=-2 VAL=-1
M V30 1 O 0.000000 1.750000 0.000000 0 CHG=-1
M V30 2 O 2.299038 0.000000 0.000000 0 CHG=-1
M V30 3 O 0.000000 2.750000 0.000000 0 CHG=-1
M V30 4 O 3.299038 0.000000 0.000000 0 CHG=-2
M V30 5 Na 0.000000 3.750000 0.000000 0 CHG=1 VAL=-1
M V30 6 Mg 4.299038 0.000000 0.000000 0 CHG=2 VAL=-1
M V30 7 Al 0.000000 4.750000 0.000000 0 CHG=3 VAL=-1
M V30 8 Si 5.299038 0.000000 0.000000 0 VAL=-1
M V30 9 O 1.299038 0.750000 0.000000 0
M V30 10 C 0.000000 0.000000 0.000000 0
M V30 11 O -1.299038 0.750000 0.000000 0 CHG=-1 VAL=1
M V30 11 O -1.299038 0.750000 0.000000 0 CHG=-1
M V30 12 O -0.000000 -1.500000 0.000000 0
M V30 END ATOM
M V30 BEGIN BOND
Expand Down
2 changes: 1 addition & 1 deletion Code/GraphMol/MarvinParse/test_data/Smiles1.expected.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ M V30 COUNTS 9 9 0 0 0
M V30 BEGIN ATOM
M V30 1 N 3.750000 -1.299038 0.000000 0
M V30 2 C 3.000000 0.000000 0.000000 0
M V30 3 O 3.750000 1.299038 0.000000 0 CHG=-1 VAL=1
M V30 3 O 3.750000 1.299038 0.000000 0 CHG=-1
M V30 4 C 1.500000 0.000000 0.000000 0
M V30 5 C 0.750000 -1.299038 0.000000 0
M V30 6 C -0.750000 -1.299038 0.000000 0
Expand Down

0 comments on commit a0a21e6

Please sign in to comment.