Skip to content

Commit 834e70e

Browse files
committed
isMetal utility function.
1 parent 21de172 commit 834e70e

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

base/core/src/main/java/org/openscience/cdk/config/Elements.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525
package org.openscience.cdk.config;
2626

27+
import org.openscience.cdk.interfaces.IAtom;
2728
import org.openscience.cdk.interfaces.IElement;
2829

2930
import java.util.HashMap;
@@ -506,4 +507,45 @@ public static Elements ofString(final String str) {
506507
// Incorrect spelling
507508
@Deprecated
508509
public final static IElement PLUTOMNIUM = PLUTONIUM;
510+
511+
/**
512+
* Utility method to determine if an atomic number is a metal.
513+
* @param atno atomic number
514+
* @return the atomic number is a metal (or not)
515+
*/
516+
public static boolean isMetal(int atno) {
517+
switch (atno) {
518+
case 0: // *
519+
case 1: // H
520+
case 2: // He
521+
case 6: // C
522+
case 7: // N
523+
case 8: // O
524+
case 9: // F
525+
case 10: // Ne
526+
case 15: // P
527+
case 16: // S
528+
case 17: // Cl
529+
case 18: // Ar
530+
case 34: // Se
531+
case 35: // Br
532+
case 36: // Kr
533+
case 53: // I
534+
case 54: // Xe
535+
case 86: // Rn
536+
return false;
537+
}
538+
return true;
539+
}
540+
541+
/**
542+
* Utility method to determine if an atom is a metal.
543+
*
544+
* @param atom atom
545+
* @return the atom is a metal (or not)
546+
*/
547+
public static boolean isMetal(IAtom atom) {
548+
return atom.getAtomicNumber() != null &&
549+
isMetal(atom.getAtomicNumber());
550+
}
509551
}

0 commit comments

Comments
 (0)