1package denoptim.molecularmodeling.zmatrix;
3import java.util.ArrayList;
4import java.util.Collections;
5import java.util.HashSet;
9import org.openscience.cdk.interfaces.IAtom;
10import org.openscience.cdk.interfaces.IAtomContainer;
11import org.openscience.cdk.interfaces.IBond;
13import denoptim.constants.DENOPTIMConstants;
14import denoptim.exception.DENOPTIMException;
15import denoptim.utils.ConnectedLigand;
16import denoptim.utils.ConnectedLigandComparator;
17import denoptim.utils.MathUtils;
18import denoptim.utils.MoleculeUtils;
19import denoptim.utils.ObjectPair;
20import denoptim.utils.RotationalSpaceUtils;
75 List<ZMatrixBond> bondsToRemove =
new ArrayList<>();
78 if (bond.getAtm1() == atm || bond.getAtm2() == atm)
80 bondsToRemove.add(bond);
116 List<int[]> bondData =
new ArrayList<>();
119 bondData.add(
new int[] {bond.getAtm1().
getId(),
120 bond.getAtm2().getId()});
156 List<int[]> bondsToAdd =
new ArrayList<>();
159 boolean found =
false;
163 if (atm.getBondRefAtom() ==
null)
166 if ((atm == bond.getAtm1() && atm.getBondRefAtom() == bond.getAtm2()) ||
167 (atm == bond.getAtm2() && atm.getBondRefAtom() == bond.getAtm1()))
175 bondsToAdd.add(
new int[] {bond.getAtm1().
getId(),
176 bond.getAtm2().getId()});
190 List<int[]> bondsToDel =
new ArrayList<>();
191 for (
int i = 0; i <
lstAtoms.size(); i++)
198 boolean found =
false;
201 if ((atm == bond.getAtm1() && atm.
getBondRefAtom() == bond.getAtm2()) ||
202 (atm == bond.getAtm2() && atm.
getBondRefAtom() == bond.getAtm1()))
391 for (
int ia=0; ia<
lstAtoms.size(); ia++)
395 if ((idxJ==idx1 && idxK==idx2) || (idxJ==idx2 && idxK==idx1))
398 if (c !=
null && c == 0)
440 List<ZMatrixBond> bondsToDel =
new ArrayList<>();
443 if ((bond.getAtm1() == a1 && bond.getAtm2() == a2) ||
444 (bond.getAtm1() == a2 && bond.getAtm2() == a1))
446 bondsToDel.add(bond);
492 atom.getId(), atom.getSymbol(), atom.getType(),
494 atom.getBondLength(),
495 atom.getAngleValue(),
496 atom.getAngle2Value(),
497 atom.getChiralFlag()));
500 for (
int i = 0; i <
lstAtoms.size(); i++)
547 boolean debug =
false;
549 String doneBnd =
"visitedBond";
550 for (
int i=0; i<mol.getAtomCount(); i++)
559 Double bondLength =
null;
560 Double angleValue =
null;
561 Double angle2Value =
null;
562 Integer chiralFlag =
null;
564 IAtom atmI = mol.getAtom(i);
567 System.err.println(
"Atom to IC: "
575 bondLength = atmI.getPoint3d().distance(mol.getAtom(i2).getPoint3d());
576 mol.getBond(atmI,mol.getAtom(i2)).setProperty(doneBnd,
"T");
586 mol.getAtom(i2).getPoint3d(),
587 mol.getAtom(i3).getPoint3d());
599 mol.getAtom(i2).getPoint3d(),
600 mol.getAtom(i4).getPoint3d());
604 mol.getAtom(i2).getPoint3d(),
605 mol.getAtom(i3).getPoint3d(),
606 mol.getAtom(i4).getPoint3d());
612 IAtom atmJ = mol.getAtom(i2);
613 IAtom atmK = mol.getAtom(i3);
614 IAtom atmL = mol.getAtom(i4);
617 atmI.getPoint3d(), atmJ.getPoint3d(),
618 atmK.getPoint3d(), atmL.getPoint3d());
619 double valueIJKL = angle2Value;
623 IBond bnd = mol.getBond(atmJ, atmK);
626 Object cnstrDefObj = bnd.getProperty(
628 if (cnstrDefObj!=
null)
634 IAtom[] atomsABCD = (IAtom[]) cnstrDefObj;
635 double cnstrABCD = (double) bnd.getProperty(
637 if (atmJ==atomsABCD[2] && atmK==atomsABCD[1])
641 atomsABCD =
new IAtom[]{
642 atomsABCD[3], atomsABCD[2],
643 atomsABCD[1], atomsABCD[0]};
646 cnstrABCD = 360.0 - cnstrABCD;
648 cnstrABCD = cnstrABCD - 360.0;
653 atomsABCD[0].getPoint3d(),
654 atomsABCD[1].getPoint3d(),
655 atomsABCD[2].getPoint3d(),
656 atomsABCD[3].getPoint3d());
657 double correctionABCD = cnstrABCD - valueABCD;
659 angle2Value = angle2Value + correctionABCD;
661 if (angle2Value > 360)
663 angle2Value = angle2Value - 360;
664 }
else if (angle2Value < -360) {
665 angle2Value = angle2Value + 360;
670 System.err.println(
" dihedral constrain along "
671 + i2 +
"-" + i3 +
": "
672 + valueIJKL +
" -> " + angle2Value
673 +
" (changed by " + correctionABCD +
")");
681 System.err.println(
" i4 = "+ i4 +
" angle2Value: " + angle2Value +
" " + i5);
689 atyp = atypObj.toString();
692 bndRef, angleRef, angle2Ref,
693 bondLength, angleValue, angle2Value,
699 for (IBond b : mol.bonds())
701 zmat.
addBond(mol.indexOf(b.getAtom(0)),
702 mol.indexOf(b.getAtom(1)));
715 List<ConnectedLigand> candidates =
new ArrayList<ConnectedLigand>();
716 for (IAtom nbr : mol.getConnectedAtomsList(mol.getAtom(i1)))
718 if (mol.indexOf(nbr) < i1)
725 int i2 = mol.indexOf(candidates.get(0).getAtom());
733 List<ConnectedLigand> candidates =
new ArrayList<ConnectedLigand>();
734 for (IAtom nbr : mol.getConnectedAtomsList(mol.getAtom(i2)))
736 if ((mol.indexOf(nbr) < i1) && (nbr != mol.getAtom(i1)))
743 int i3 = mol.indexOf(candidates.get(0).getAtom());
752 boolean debug =
false;
754 IAtom atmI1 = mol.getAtom(i1);
755 IAtom atmI2 = mol.getAtom(i2);
756 IAtom atmI3 = mol.getAtom(i3);
757 List<ConnectedLigand> candidates =
new ArrayList<ConnectedLigand>();
758 if (zmat.usesProperDihedral(i2, i3) ||
762 for (IAtom nbr : mol.getConnectedAtomsList(atmI2))
766 System.err.println(
" Eval. 3rd (ANG): " +
768 + mol.indexOf(nbr) +
" "
769 + (mol.indexOf(nbr) < i1) +
" "
770 + (nbr != atmI1) +
" "
773 if ((mol.indexOf(nbr) < i1) && (nbr != atmI1) &&
788 System.err.println(
" ...but collinear with "
790 +
" (i4-i2-i3: " + dbcAng
800 for (IAtom nbr : mol.getConnectedAtomsList(atmI3))
804 System.err.println(
" Eval. 3rd (TOR): "
806 + mol.indexOf(nbr) +
" "
807 + (mol.indexOf(nbr) < i1) +
" "
808 + (nbr != atmI1) +
" "
811 if ((mol.indexOf(nbr) < i1) && (nbr != atmI1) &&
820 if (candidates.size() == 0)
822 String msg =
"Unable to make internal coordinates. Please, "
823 +
"consider the use of dummy atoms in proximity "
824 +
"of atom " + zmat.getAtom(i1+1);
827 int i4 = mol.indexOf(candidates.get(0).getAtom());
839 for (IAtom nbr : mol.getConnectedAtomsList(a))
841 if (mol.indexOf(nbr) < i)
859 if (o.getClass() != getClass())
865 if (this.
id ==
null ? other.
id !=
null : !
this.id.equals(other.
id))
869 if (this.lstAtoms.size() != other.
lstAtoms.size())
873 for (
int i = 0; i < this.lstAtoms.size(); i++)
875 if (!this.lstAtoms.get(i).equals(other.
lstAtoms.get(i)))
880 if (this.lstBonds.size() != other.
lstBonds.size())
885 Set<String> thisBondIds =
new HashSet<>();
888 int id1 = bond.getAtm1().getId();
889 int id2 = bond.getAtm2().getId();
891 String bondId = Math.min(id1, id2) +
"-" + Math.max(id1, id2);
892 thisBondIds.add(bondId);
895 Set<String> otherBondIds =
new HashSet<>();
900 String bondId = Math.min(id1, id2) +
"-" + Math.max(id1, id2);
901 otherBondIds.add(bondId);
904 return thisBondIds.equals(otherBondIds);
913 result = 31 * result + (
id !=
null ?
id.hashCode() : 0);
914 result = 31 * result +
lstAtoms.size();
917 result = 31 * result + atom.hashCode();
919 result = 31 * result +
lstBonds.size();
922 result = 31 * result + bond.hashCode();
General set of constants used in DENOPTIM.
static final Object ATMPROPATOMTYPE
NAme of the property used to hold atom types, if any.
Representation of an atom in the ZMatrix.
Double getAngle2Value()
Get the angle2 value.
Integer getChiralFlag()
Get the chiral flag.
int getId()
Get the id of the atom.
void setBondRefAtom(ZMatrixAtom bondRefAtom)
Package-private setter for bond reference atom (used for cloning).
ZMatrixAtom getBondRefAtom()
Get the bond reference atom.
ZMatrixAtom getAngle2RefAtom()
Get the angle2 reference atom.
void setAngle2RefAtom(ZMatrixAtom angle2RefAtom)
Package-private setter for angle2 reference atom (used for cloning).
Double getBondLength()
Get the bond length.
void setAngleRefAtom(ZMatrixAtom angleRefAtom)
Package-private setter for angle reference atom (used for cloning).
Double getAngleValue()
Get the angle value.
ZMatrixAtom getAngleRefAtom()
Get the angle reference atom.
Representation of a bond in the ZMatrix.
ZMatrixAtom getAtm2()
Get the second atom in the bond.
ZMatrixAtom getAtm1()
Get the first atom in the bond.
Representation of an atom container's geometry with internal coordinates.
static int getFirstRefAtomId(int i1, IAtomContainer mol)
List< int[]> getBondsToDel()
Get the bonds to delete from the ZMatrix.
int getIndex(ZMatrixAtom atm)
Get the index of the atom.
List< int[]> getBondData()
Get the bond data for the ZMatrix.
static ObjectPair getThirdRefAtomId(int i1, int i2, int i3, IAtomContainer mol, ZMatrix zmat)
void delBond(int a1, int a2)
Delete the bond between the two atoms at the given indices.
int getAtomCount()
Get the number of atoms in the ZMatrix.
Integer getChiralFlag(int index)
Get the chiral flag for the atom at the given index.
static int getSecondRefAtomId(int i1, int i2, IAtomContainer mol)
void removeAtom(ZMatrixAtom atm)
Remove an atom from the ZMatrix.
static int countPredefinedNeighbours(int i, IAtom a, IAtomContainer mol)
List< ZMatrixAtom > getAtoms()
Get the atoms in the ZMatrix.
String getId()
Get the id of the ZMatrix.
int getBondCount()
Get the number of bonds in the ZMatrix.
ZMatrixAtom getAngleRefAtom(int index)
Get the angle reference atom for the atom at the given index.
int getBondRefAtomIndex(int index)
Get the index of the bond reference atom for the atom at the given index.
ZMatrix clone()
Clone the ZMatrix.
static ZMatrix getZMatrixFromIAC(IAtomContainer mol)
Convert IAtomContainer to ZMatrix.
Double getBondLength(int index)
Get the bond length for the atom at the given index.
ZMatrixBond getBond(int index)
Get the bond at the given index.
boolean usesProperDihedral(int idx1, int idx2)
Check if the dihedral between the two atoms at the given indices uses proper torsion.
void setId(String id)
Set the id of the ZMatrix.
void addBond(int a1, int a2)
Add a bond between the two atoms at the given indices.
void addBond(ZMatrixAtom a1, ZMatrixAtom a2)
Add a bond between the two atoms.
String id
Identifier of this ZMatrix.
List< int[]> getBondsToAdd()
Get the bonds to add to the Z-matrix.
ZMatrixAtom getBondRefAtom(int index)
Get the bond reference atom for the atom at the given index.
ZMatrixAtom getAngle2RefAtom(int index)
Get the second angle reference atom for the atom at the given index.
ZMatrix()
Constructor for ZMatrix.
Double getAngle2Value(int index)
Get the angle2 angle for the atom at the given index.
Double getAngleValue(int index)
Get the bond angle for the atom at the given index.
ZMatrixAtom getAtom(int index)
Get the atom at the given index.
void delBond(ZMatrixAtom a1, ZMatrixAtom a2)
Delete the bond between the two atoms.
List< ZMatrixAtom > lstAtoms
All atoms and pseudoAtoms mentioned in the Zmatrix.
void addAtom(ZMatrixAtom atom)
Add an atom to the ZMatrix.
int getAngle2RefAtomIndex(int index)
Get the index of the second angle reference atom for the atom at the given index.
List< ZMatrixBond > lstBonds
All bonds in the system, whether included or not in the Z-matrix intrinsic connections.
int getAngleRefAtomIndex(int index)
Get the index of the angle reference atom for the atom at the given index.
Compare two ConnectedLigand according to the number of connected atoms and the mass number.
A ConnectedLigand is just an atom with an explicit field reporting the number of connected atoms.
Some useful math operations.
static double angle(Point3d a, Point3d b, Point3d c)
Calculate the angle between the 3 points.
static double torsion(Point3d p1, Point3d p2, Point3d p3, Point3d p4)
Calculate the torsion angle between the 4 points.
Utilities for molecule conversion.
static String getSymbolOrLabel(IAtom atm)
Gets either the elemental symbol (for standard atoms) of the label (for pseudo-atoms).
This class is the equivalent of the Pair data structure used in C++ Although AbstractMap....
Tool box for definition and management of the rotational space, which is given by the list of rotatab...
static final String PROPERTY_ROTDBDCSTR_DEF
static final String PROPERTY_ROTDBDCSTR_VALUE