Skip to content

Commit

Permalink
Added dependencies, formatted sources.
Browse files Browse the repository at this point in the history
  • Loading branch information
javadev authored and egonw committed Feb 6, 2022
1 parent 8637305 commit a589827
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 334 deletions.
Expand Up @@ -19,25 +19,18 @@ and associated documentation files (the "Software"), to deal in the Software wit
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/


package org.openscience.cdk.structgen.maygen;

/**
* <p>
* This class is for the early boundary conditions class of MAYGEN package.
* Users can define their early boundary conditions for the structure generation process.
* This will help to avoid post processing filtering.
* </p>
*
* <p>
* For example, with detectTripleBonds, users can avoid the generation of molecular structures
* with triple bonds. Users can add their functions, the early boundary conditions, here.
* </p>
* This class is for the early boundary conditions class of MAYGEN package. Users can define their
* early boundary conditions for the structure generation process. This will help to avoid post
* processing filtering.
*
* <p>For example, with detectTripleBonds, users can avoid the generation of molecular structures
* with triple bonds. Users can add their functions, the early boundary conditions, here.
*
* @author MehmetAzizYirik <mehmetazizyirik@outlook.com> <0000-0001-7520-7215@orcid.org>
*
* @cdk.module structgen
*
*/
class BoundaryConditions {

Expand All @@ -46,10 +39,9 @@ private BoundaryConditions() {}
/**
* No triple bonds.
*
* @param mat int[][] the adjacency matrix
* @param mat int[][] the adjacency matrix
* @return boolean
*/

public static boolean detectTripleBonds(int[][] mat) {
int length = mat.length;
for (int i = 0; i < length; i++) {
Expand All @@ -65,7 +57,7 @@ public static boolean detectTripleBonds(int[][] mat) {
/**
* No adjacent double bonds.
*
* @param mat int[][] the adjacency matrix
* @param mat int[][] the adjacency matrix
* @return boolean
*/
public static boolean detectAdjacentDoubleBonds(int[][] mat) {
Expand All @@ -87,11 +79,10 @@ public static boolean detectAdjacentDoubleBonds(int[][] mat) {
/**
* No allenes.
*
* @param mat int[][]the adjacency matrix
* @param symbols String[] atom symbols
* @param mat int[][]the adjacency matrix
* @param symbols String[] atom symbols
* @return boolean
*/

public static boolean detectAllenes(int[][] mat, String[] symbols) {
boolean check = false;
int count;
Expand All @@ -116,11 +107,10 @@ public static boolean detectAllenes(int[][] mat, String[] symbols) {
* After defining the above early boundary conditions, they need to be added to the
* boundaryConditionCheck function.
*
* @param mat int[][] adjacency matrix
* @param symbolArray String[] symbolArray
* @param mat int[][] adjacency matrix
* @param symbolArray String[] symbolArray
* @return boolean
*/

public static boolean boundaryConditionCheck(int[][] mat, String[] symbolArray) {
boolean check = true;

Expand Down
Expand Up @@ -30,15 +30,11 @@ and associated documentation files (the "Software"), to deal in the Software wit
import org.openscience.cdk.interfaces.IAtomContainer;

/**
* <p>
* The generation process in maygen class is given here. Due to the parallelization, the generation
* functions are kept in a separate class.
* </p>
* functions are kept in a separate class.
*
* @author MehmetAzizYirik <mehmetazizyirik@outlook.com> <0000-0001-7520-7215@orcid.org>
*
* @cdk.module structgen
*
*/
class Generation {
private final Maygen maygen;
Expand All @@ -49,10 +45,9 @@ public Generation(Maygen maygen) {

/**
* The initial function of the generation process
*
* @param degree int[] the list of node degrees ( the atom valences )
*
* @param degree int[] the list of node degrees ( the atom valences )
*/

public void run(int[] degree) {
IAtomContainer atomContainer = maygen.getBuilder().newInstance(IAtomContainer.class);
int[] partSize = new int[] {0};
Expand Down
Expand Up @@ -28,18 +28,14 @@ and associated documentation files (the "Software"), to deal in the Software wit
import java.util.stream.IntStream;

/**
* <p>
* The hydrogen distribution process is a preliminary step in the generation.
* The pre-distribution of hydrogens accelerates the generation. For a given chemical
* formula, all the possible distributions of the hydrogen atoms to the hetero atoms
* are generated.For example, C6H6 has 6 hydrogens and 6 carbons. There are 7 unique
* possible distribution of these hydrogens to these carbons.
* </p>
* The hydrogen distribution process is a preliminary step in the generation. The pre-distribution
* of hydrogens accelerates the generation. For a given chemical formula, all the possible
* distributions of the hydrogen atoms to the hetero atoms are generated.For example, C6H6 has 6
* hydrogens and 6 carbons. There are 7 unique possible distribution of these hydrogens to these
* carbons.
*
* @author MehmetAzizYirik <mehmetazizyirik@outlook.com> <0000-0001-7520-7215@orcid.org>
*
* @cdk.module structgen
*
*/
class HydrogenDistributor {
private int[] capacity;
Expand All @@ -51,11 +47,10 @@ class HydrogenDistributor {
/**
* Adding new element to an int array.
*
* @param a int[] a
* @param e int[] e
* @param a int[] a
* @param e int[] e
* @return int[]
*/

public int[] addElement(int[] a, int e) {
a = Arrays.copyOf(a, a.length + 1);
a[a.length - 1] = e;
Expand All @@ -65,11 +60,10 @@ public int[] addElement(int[] a, int e) {
/**
* Summing the entries of an array.
*
* @param list int[] list
* @param index int entry index
* @param list int[] list
* @param index int entry index
* @return int
*/

public int sum(int[] list, int index) {
int sum = 0;
for (int i = 0; i <= index; i++) {
Expand All @@ -80,12 +74,11 @@ public int sum(int[] list, int index) {

/**
* Setting the global variables based on the initial partition and degrees.
*
* @param partition int[] atom partition
* @param degrees int[] atom valences
* @return int[]
*
* @param partition int[] atom partition
* @param degrees int[] atom valences
* @return int[]
*/

public int[] setValues(int[] partition, int[] degrees) {
int partitionSize = partition.length;
int[] localCapacity = new int[partitionSize];
Expand All @@ -109,11 +102,10 @@ public int[] setValues(int[] partition, int[] degrees) {

/**
* Summing entries of an int array
*
* @param array int[] array
* @return int
*
* @param array int[] array
* @return int
*/

public int sum(int[] array) {
int sum = 0;
for (int i = 0; i < array.length; i++) {
Expand All @@ -124,11 +116,10 @@ public int sum(int[] array) {

/**
* Combining list of int arrays.
*
* @param arrays List<int[]> list of int arrays
* @return int[]
*
* @param arrays List<int[]> list of int arrays
* @return int[]
*/

public int[] mergeArrays(List<int[]> arrays) {
int size = 0;
for (int[] array : arrays) {
Expand All @@ -146,12 +137,11 @@ public int[] mergeArrays(List<int[]> arrays) {

/**
* Combining 2 int arrays.
*
* @param a int[] int array
* @param b int[] int array
* @return int[]
*
* @param a int[] int array
* @param b int[] int array
* @return int[]
*/

public int[] arraySum(int[] a, int[] b) {
List<int[]> arrays = new ArrayList<>();
arrays.add(a);
Expand All @@ -161,11 +151,10 @@ public int[] arraySum(int[] a, int[] b) {

/**
* Combining list of int arrays.
*
* @param lists LinkedList<List<int[]>> lists
* @return List<int[]>
*
* @param lists LinkedList<List<int[]>> lists
* @return List<int[]>
*/

public List<int[]> combineArrays(LinkedList<List<int[]>> lists) {
List<int[]> comb = new ArrayList<>(lists.removeFirst());
while (!lists.isEmpty()) {
Expand All @@ -184,11 +173,10 @@ public List<int[]> combineArrays(LinkedList<List<int[]>> lists) {
/**
* To initialise the inputs and run the functions while recording the duration time.
*
* @param partition int[] partition
* @param degrees int[] degrees
* @param partition int[] partition
* @param degrees int[] degrees
* @return List<int[]>
*/

public List<int[]> run(int[] partition, int[] degrees) {
int partitionSize = partition.length;
int hydrogen = partition[partitionSize - 1];
Expand Down Expand Up @@ -224,13 +212,11 @@ public List<int[]> run(int[] partition, int[] degrees) {
/**
* These functions are built for the integer partitioning problem.
*
* @param n int total number of hydrogens
* @param d int total number of isotopes to distribute hydrogens
* @param n int total number of hydrogens
* @param d int total number of isotopes to distribute hydrogens
* @param depth int starting from zero until the number of isotopes recursively filling.
*
* @return List<int[]>
*/

public List<int[]> partition(int n, int d, int depth) {
if (d == depth) {
List<int[]> array = new ArrayList<>();
Expand All @@ -244,13 +230,11 @@ public List<int[]> partition(int n, int d, int depth) {
/**
* Subfunction of partition function.
*
* @param n int total number of hydrogens
* @param d int total number of isotopes to distribute hydrogens
* @param n int total number of hydrogens
* @param d int total number of isotopes to distribute hydrogens
* @param depth int starting from zero until the number of isotopes recursively filling.
*
* @return List<int[]>
*/

public List<int[]> buildArray(int n, int d, int depth) {
List<int[]> array = new ArrayList<>();
IntStream range = IntStream.rangeClosed(0, n);
Expand All @@ -265,14 +249,12 @@ public List<int[]> buildArray(int n, int d, int depth) {
/**
* These functions are built for the integer partitioning problem.
*
* @param d int total number of isotopes to distribute hydrogens
* @param List<int[]> List<int[]> list of partition
* @param i int entry
* @param item int[] new partition
*
* @param d int total number of isotopes to distribute hydrogens
* @param List<int[]> List<int[]> list of partition
* @param i int entry
* @param item int[] new partition
* @return List<int[]>
*/

public void buildArrayItem(int d, List<int[]> array, int i, int[] item) {
if (i <= capacity[item.length]) {
item = addElement(item, i);
Expand All @@ -289,12 +271,10 @@ public void buildArrayItem(int d, List<int[]> array, int i, int[] item) {
/**
* Adding zeros to the end of an array.
*
* @param array int[] partition
* @param zeros int number of zeros
*
* @param array int[] partition
* @param zeros int number of zeros
* @return int[]
*/

public int[] addZeros(int[] array, int zeros) {
for (int i = 0; i < zeros; i++) {
array = addElement(array, 0);
Expand All @@ -303,27 +283,24 @@ public int[] addZeros(int[] array, int zeros) {
}

/**
* Ordering the int array in descending order.
*
* @param array int[] array
*
* Ordering the int array in descending order.
*
* @param array int[] array
* @return int[]
*/

public int[] descendingOrderArray(int[] arr) {
return Arrays.stream(arr).boxed().sorted().mapToInt(Integer::intValue).toArray();
}

/**
* Distributing number of hydrogens in an unique way to a number of isotopes.
*
* @param arrays List<int[]> list of output arrays
* @param hydrogen int number of hydrogens to add
* @param array int[] array
* @param valence int atom valence
* @param numAtom int number of atoms in a given index
*
* @param arrays List<int[]> list of output arrays
* @param hydrogen int number of hydrogens to add
* @param array int[] array
* @param valence int atom valence
* @param numAtom int number of atoms in a given index
*/

public void distribute(List<int[]> arrays, int hydrogen, int[] arr, int valence, int numAtom) {
if (hydrogen == 0 && sum(arr) == hydrogens2distribute) {
if (arr.length != numAtom) {
Expand All @@ -347,14 +324,13 @@ public void distribute(List<int[]> arrays, int hydrogen, int[] arr, int valence,

/**
* Subfunction of the distribute functon for the case when (numAtom - arr.length == 1)
*
* @param arrays List<int[]> list of output arrays
* @param hydrogen int number of hydrogens to add
* @param array int[] array
* @param valence int atom valence
* @param numAtom int number of atoms in a given index
*
* @param arrays List<int[]> list of output arrays
* @param hydrogen int number of hydrogens to add
* @param array int[] array
* @param valence int atom valence
* @param numAtom int number of atoms in a given index
*/

public void numAtomMinusArrLengthEqualsOne(
List<int[]> arrays, int hydrogen, int[] arr, int valence, int numAtom) {
int add = Math.min(hydrogen, valence);
Expand Down

0 comments on commit a589827

Please sign in to comment.