Skip to content

Commit

Permalink
Preliminary support for MRV Data Sgroup tags.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmay committed Nov 27, 2022
1 parent 4c78655 commit 52d372e
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public class MDLV2000Reader extends DefaultChemObjectReader {

/** Valid pseudo labels. */
private static final Set<String> PSEUDO_LABELS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList("*","A","Q","L","LP","R","R#")));

public MDLV2000Reader() {
this(new StringReader(""));
}
Expand Down Expand Up @@ -466,7 +466,7 @@ private IAtomContainer readAtomContainer(IAtomContainer molecule) throws CDKExce
}
}

// read PROPERTY block
// read PROPERTY block and SGroups
readPropertiesFast(input, outputContainer, nAtoms);

// read potential SD file data between M END and $$$$
Expand Down Expand Up @@ -895,7 +895,9 @@ IBond readBondFast(String line, IChemObjectBuilder builder, IAtom[] atoms, int[]
* @param nAtoms the number of atoms in the atoms block
* @throws IOException low-level IO error
*/
void readPropertiesFast(final BufferedReader input, final IAtomContainer container, final int nAtoms)
void readPropertiesFast(final BufferedReader input,
final IAtomContainer container,
final int nAtoms)
throws IOException, CDKException {
String line;

Expand Down Expand Up @@ -1084,7 +1086,7 @@ void readPropertiesFast(final BufferedReader input, final IAtomContainer contain
index = readMolfileInt(line, st) - 1;
int value = readMolfileInt(line, st + 4);
SPIN_MULTIPLICITY multiplicity = SPIN_MULTIPLICITY.ofValue(value);

container.getAtom(offset + index).setProperty(CDKConstants.SPIN_MULTIPLICITY, multiplicity);

for (int e = 0; e < multiplicity.getSingleElectrons(); e++)
Expand Down Expand Up @@ -1430,6 +1432,37 @@ void readPropertiesFast(final BufferedReader input, final IAtomContainer contain


if (!sgroups.isEmpty()) {

for (Sgroup sgroup : sgroups.values()) {
if (sgroup.getType() != SgroupType.CtabData)
continue;
String key = sgroup.getValue(SgroupKey.DataFieldName);
String val = sgroup.getValue(SgroupKey.Data);
switch (key) {
case "MRV_IMPLICIT_H":
final int implh;
if (val.equals("IMPL_H0"))
implh = 0;
else if (val.equals("IMPL_H1"))
implh = 1;
else if (val.equals("IMPL_H2"))
implh = 2;
else
break; // unlikely/rare/not supported
for (IAtom atom : sgroup.getAtoms())
atom.setImplicitHydrogenCount(implh);
break;
case "MRV_COORDINATE_BOND_TYPE":
IAtom[] atoms = sgroup.getAtoms().toArray(new IAtom[0]);
if (atoms.length == 2) {
IBond bond = container.getBond(atoms[0], atoms[1]);
if (bond != null)
bond.setOrder(IBond.Order.UNSET);
}
break;
}
}

// load Sgroups into molecule, first we downcast
List<Sgroup> sgroupOrgList = new ArrayList<>(sgroups.values());
List<Sgroup> sgroupCpyList = new ArrayList<>(sgroupOrgList.size());
Expand Down Expand Up @@ -2443,7 +2476,7 @@ enum PropertyKey {

/** ACDLabs Atom Label */
M_ZZC,

/** End of Block. */
M_END,

Expand Down

0 comments on commit 52d372e

Please sign in to comment.