Exemple #1
0
        /// <summary>
        /// 从选定官能团的位置数组转换成FP4.
        /// selectedFGs数组中的每个数字代表该分子含有官能团表中这个数字所代表的官能团
        /// </summary>
        /// <param name="selectedFGs">含有的官能团编号,是个整数数组</param>
        /// <returns>Openbabel数据库格式的整数数组[16]</returns>
        public static List <long> GenerateFp4(List <int> selectedFGs)
        {
            OBConversion  conv        = new OBConversion(); //一定要有这句才不会报错
            OBFingerprint fingerprint = OBFingerprint.FindFingerprint("FP4");
            VectorUInt    fp4         = new VectorUInt(16);

            //初始化_fp4
            for (var i = 0; i < 16; i++)
            {
                fp4.Add(0);
            }

            foreach (var bit in selectedFGs)
            {
                fingerprint.SetBit(fp4, (uint)bit); //设置FP4
            }

            return(fp4.Select(u => (long)u).ToList()); //
        }
Exemple #2
0
        /// <summary>
        /// 生成指纹码
        /// </summary>
        /// <param name="FpType">FP2 or FP4</param>
        /// <returns></returns>
        private long[] GetFP(string fpType)
        {
            VectorUInt    _fp  = new VectorUInt();
            OBFingerprint _FPC = OBFingerprint.FindFingerprint(fpType);

            _FPC.GetFingerprint(mol, _fp);

            if ((fpType == "FP2" && _fp.Count != 32) || (fpType == "FP4" && _fp.Count != 16))
            {
                throw new Exception("获取FP错误,请确认OpenBabel GUI已正确安装安装, 环境变量BABEL_DATADIR在当前用户下已经正确设置");
            }

            long[] fp = new long[_fp.Count];

            for (int i = 0; i < _fp.Count; i++)
            {
                fp[i] = _fp[i]; // uint type automatically cast to long type
            }

            return(fp);
        }