Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preliminary support for MRV Data Sgroup tags. #939

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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