com.actelion.research.chem.phesa.pharmacophore.ChargedGroupDetector Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of openchemlib Show documentation
Show all versions of openchemlib Show documentation
Open Source Chemistry Library
package com.actelion.research.chem.phesa.pharmacophore;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import com.actelion.research.chem.RingCollection;
import com.actelion.research.chem.StereoMolecule;
import com.actelion.research.chem.phesa.pharmacophore.pp.ChargePoint;
/**
* derives charged groups
* @author wahljo1
*
*/
public class ChargedGroupDetector {
private StereoMolecule mol;
private List> chargedGroups;
private RingCollection ringCollection;
public ChargedGroupDetector(StereoMolecule mol) {
this.mol = mol;
chargedGroups = new ArrayList>();
ringCollection = mol.getRingSet();
}
public ArrayList detect() {
ArrayList chargePoints = new ArrayList();
//detect tetrazoles
for(int r=0;r tetrazole = new ArrayList();
int totCharge = 0;
int[] ringAtoms = ringCollection.getRingAtoms(r);
for(Integer atom : ringAtoms) {
if(alreadyDetected(atom)) continue;
if(mol.getAtomicNo(atom)==7 && mol.isAromaticAtom(atom) && mol.getConnAtoms(atom)<=2) {
tetrazole.add(atom);
totCharge += mol.getAtomCharge(atom);
}
}
if(tetrazole.size()==4 && totCharge<0) {
chargedGroups.add(tetrazole);
ChargePoint cp = new ChargePoint(mol,tetrazole.get(0),Arrays.asList(tetrazole.get(1),
tetrazole.get(2),tetrazole.get(3)),totCharge);
chargePoints.add(cp);
}
}
for(int a=0;a group = new ArrayList<>();
group.add(cp.getChargeAtom());
group.addAll(cp.getNeighbours());
chargedGroups.add(group);
}
else if(mol.getAtomicNo(a)==7) {
int carbonCenter = -1;
int charge = 0;
List neighbours = new ArrayList<>();
if(!mol.isAromaticAtom(a) && mol.getConnAtoms(a)<=2) { //HNR2 or H2NR
neighbours.add(a);
charge+=mol.getAtomCharge(a);
int nDBs = 0;
for(int i=0;i1 && charge>0) {
ChargePoint cp = new ChargePoint(mol,carbonCenter,neighbours,charge);
chargePoints.add(cp);
ArrayList group = new ArrayList<>();
group.add(cp.getChargeAtom());
group.addAll(cp.getNeighbours());
chargedGroups.add(group);
}
}
}
if(alreadyDetected(a))continue;
else {
int charge = mol.getAtomCharge(a);
if(charge!=0 && !hasCounterChargedNeighbour(a)) {
charge = charge>0 ? 1 : -1;
ChargePoint cp = new ChargePoint(mol,a,new ArrayList(),charge);
chargePoints.add(cp);
ArrayList group = new ArrayList<>();
group.add(a);
chargedGroups.add(group);
}
}
}
return chargePoints;
}
public List> getChargedGroups() {
return chargedGroups;
}
private boolean hasCounterChargedNeighbour(int a) {
for(int aa=0;aa neighbours = new ArrayList<>();
neighbours.add(atom);
int charge = 0;
charge+=mol.getAtomCharge(atom);
charge+=mol.getAtomCharge(connAtom);
int nConnected2C = mol.getConnAtoms(connAtom);
for (int i = 0; i < nConnected2C; i++) {
int indexAtom = mol.getConnAtom(connAtom, i);
if(indexAtom==atom){
continue;
}
if(mol.getAtomicNo(indexAtom) != 8){
continue;
}
charge+=mol.getAtomCharge(indexAtom);
neighbours.add(indexAtom);
}
if(charge<0) {
ChargePoint cp = new ChargePoint(mol,connAtom,neighbours,charge);
return cp;
}
} else if (mol.getAtomicNo(connAtom) == 16) { // CSOOOH
int nConnected2S = mol.getConnAtoms(connAtom);
List neighbours = new ArrayList<>();
neighbours.add(atom);
int charge = 0;
charge+=mol.getAtomCharge(atom);
charge+=mol.getAtomCharge(connAtom);
for (int i = 0; i < nConnected2S; i++) {
int indexAtom = mol.getConnAtom(connAtom, i);
if(indexAtom==atom)
continue;
if(mol.getAtomicNo(indexAtom) != 8)
continue;
charge+=mol.getAtomCharge(indexAtom);
neighbours.add(indexAtom);
}
if(charge<0) {
ChargePoint cp = new ChargePoint(mol,connAtom,neighbours,charge);
return cp;
}
} else if(mol.getAtomicNo(connAtom)==15){ // CP=O(OH)(OH)
int nConnected2P = mol.getConnAtoms(connAtom);
List neighbours = new ArrayList<>();
neighbours.add(atom);
int charge = 0;
charge+=mol.getAtomCharge(atom);
charge+=mol.getAtomCharge(connAtom);
for (int i = 0; i < nConnected2P; i++) {
int indexAtom = mol.getConnAtom(connAtom, i);
if(indexAtom==atom)
continue;
if(mol.getAtomicNo(indexAtom) != 8)
continue;
charge+=mol.getAtomCharge(indexAtom);
neighbours.add(indexAtom);
}
if(charge<0) {
ChargePoint cp = new ChargePoint(mol,connAtom,neighbours,charge);
return cp;
}
}
return null;
}
}