public HessMatrix SubMatrixByAtomsImpl0(IList <int> idxColAtoms, IList <int> idxRowAtoms) { if (SubMatrixByAtomsImpl0_selftest2) { SubMatrixByAtomsImpl0_selftest2 = false; Matrix thess1 = new double[, ] { { 0, 1, 2, 3, 4, 5 } , { 1, 2, 3, 4, 5, 6 } , { 2, 3, 4, 5, 6, 7 } , { 3, 4, 5, 6, 7, 8 } , { 4, 5, 6, 7, 8, 9 } , { 5, 6, 7, 8, 9, 0 } }; HessMatrix thess2 = HessMatrixDense.FromMatrix(thess1); HessMatrix thess3 = thess2.SubMatrixByAtomsImpl0(new int[] { 0 }, new int[] { 1 }); Matrix thess4 = new double[, ] { { 3, 4, 5 } , { 4, 5, 6 } , { 5, 6, 7 } }; HDebug.AssertToleranceMatrix(0, thess3 - thess4); } HessMatrix nhess = Zeros(idxColAtoms.Count * 3, idxRowAtoms.Count * 3); for (int nbc = 0; nbc < idxColAtoms.Count; nbc++) { for (int nbr = 0; nbr < idxRowAtoms.Count; nbr++) { int bc = idxColAtoms[nbc]; if (bc < 0) { continue; } int br = idxRowAtoms[nbr]; if (br < 0) { continue; } if (HasBlock(bc, br) == false) { continue; } MatrixByArr block = GetBlock(bc, br).CloneT(); // hessian matrix for interaction between atom i and j HDebug.Assert(block.IsZero() == false); nhess.SetBlock(nbc, nbr, block); } } return(nhess); }